opening a file via Runtime.exec() on Mac OS X

I'm having a hard time opening a file programatically on Mac OS X.

The following code works only if the filepath/filename doesn't contain a space:

String filepath;

Runtime rt = Runtime.getRuntime();

rt.exec("open " + filepath);

From a terminal, typing open + surrounding the filepath with either apostrophes or quotes and OS X will open the file no problem, even if it has spaces.

So I tried modifying my call:

filepath ="\"" + filepath +"\"";

rt.exec("open " + filepath);

...then nothing happens. No error, no popup, no exception thrown...nothing. Same thing if I use apostrophes vice quotes.

Any ideas? I'm using JDK 5.0 as 6.0 is not yet supported by Apple.

Thanks in advance.

[859 byte] By [zredbarona] at [2007-11-27 11:49:56]
# 1

assuming open is an app, not a command within a shell... what about this:

String[] cmd = { "open", filepath }; // with out quotes

rt.exec(cmd);

bsampieria at 2007-7-29 18:28:14 > top of Java-index,Java Essentials,Java Programming...
# 2

i'll give it a shot... might be a while before i can test.

thanks.

zredbarona at 2007-7-29 18:28:14 > top of Java-index,Java Essentials,Java Programming...