ProcessBuilder-command arguments that contain speech marks.

I'm using Java's ProcessBuilder to call a program. However I am having trouble when one of the command arguments contains speech marks. I've tried using escape characters in the usual way, but this doesn't seem to work.

For example this works as expected: Process p = new ProcessBuilder("programX","arg1","arg2").start();

However when arg2 needs to be surrounded by quotations for programX to understand it then this following line of code doesn't work

Process p = new ProcessBuilder("programX","arg1","\"arg2\"").start();

Any suggestions on how to solve this problem would be great

Cheers

[631 byte] By [Linda_Ha] at [2007-11-26 18:09:13]
# 1
hello lindawelcome to forumbut sorry i dont have ur questions answer
rakesh_thakura at 2007-7-9 5:41:07 > top of Java-index,Java Essentials,Java Programming...
# 2
what is the error message show?When is it shown, compile time or run time?
mlka at 2007-7-9 5:41:07 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi

Thanks for the replies.

The code compiles fine. It's a runtime error that complains about a file not existing. The file that doesn't exist is the one that should have been created from the output of the external program. So for some reason the external program is not running as expected.

It's the single program argument with the surrounding speech marks that causes an error, since when this argument is not used the external program runs fine and the file is created. I also use the command p.waitFor() to make sure that the process has finished running before the next block of code is executed. I am sure that the speech mark syntax is correct for the external program, since it works fine when run directly from the command line in this way. So it is definitely not the external program that has the error, but something is going wrong with the ProcessBuilder call and how I am using it.

Any further suggestion are much appreciated

Cheers

Linda

Linda_Ha at 2007-7-9 5:41:07 > top of Java-index,Java Essentials,Java Programming...