Spaces in File path of a command

Hi all,

I have a problem in the following API

Runtime.getRuntime.exec

("open /var/root/Desktop/Test Folder/abc.jpg");

it does not open the file mentioned but the following command

Runtime.getRuntime.exec("open /var/root/Desktop/TestFolder/abc.jpg");

it opens the file abc.jpg. the only difference between these 2 commands is spaces in "Test Folder" directory name.

Please let me know if anybody has an idea.

thanks

Message was edited by:

nav_nini

[514 byte] By [nav_ninia] at [2007-11-27 11:38:38]
# 1

("open \"/var/root/Desktop/Test Folder/abc.jpg\"");

Obviously, you need to quote the string that has spaces, since spaces on the command line normally demarcate the end of one argument and the beginning of the next.

masijade.a at 2007-7-29 17:21:22 > top of Java-index,Java Essentials,Java Programming...
# 2

Also note that to put a quote within a string, you must use:

"\""

e.g, this string printed out in cmd...

String text = "\"This is a quote\", he said";

would be: "This is a quote", he said

Just incase you didnt understand that from masijade's explanation.

Futurisdom_Developera at 2007-7-29 17:21:22 > top of Java-index,Java Essentials,Java Programming...
# 3

I Have tested with the following

("open \"/var/root/Desktop/Test Folder/abc.jpg\"");

and

("open '/var/root/Desktop/Test Folder/abc.jpg' ");

and

("open /var/root/Desktop/Test\ Folder/abc.jpg");

But no success

thanks

nav_ninia at 2007-7-29 17:21:22 > top of Java-index,Java Essentials,Java Programming...
# 4

read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

masijade.a at 2007-7-29 17:21:22 > top of Java-index,Java Essentials,Java Programming...
# 5

Thank you all

Finally i got the solution.

use

String [] cmdArray option of

Runtime.getruntime().exec(String [] cmdArray )

Best regards

Naveen

nav_ninia at 2007-7-29 17:21:22 > top of Java-index,Java Essentials,Java Programming...