problem with Runtime.getRuntime().exec command
Hi,
I am running a command in my envrionment using:
Runtime.getRuntime().exec(commandArray, null, tmpDir)
The command itself is something like this:
prog.sh 0 Y DOWNLOAD PRINTER_TYPE=APPLE
When I run my java program this works fine.
Next I try:
prog.sh 0 Y DOWNLOAD PRINTER_TYPE="APPLE"
this time my java program fails, eventhough when I run the same command from the operating system, it works.
I am using java 5 on Solaris environment.
I have also tried the new ProcessBuilder command with no success.
Seems like the exec command has a problem when the parameters have double quotes in them.
I have looked at the Runtime source code, but it runs a native function which I don't have access, so I can't tell what it is doing.
Any ideas how I can get around this.
Thanks,
[865 byte] By [
lfoggya] at [2007-11-27 2:25:38]

You need
final String[] command = {"sh","-c", "prog.sh 0 Y DOWNLOAD PRINTER_TYPE=APPLEl" };
but you also need to implement the stdout and stderr handling recommendations in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
Also, make sure that prog.sh is in a directory that is on your PATH or specify the complete path.
Message was edited by:
sabre150
I guess you are missing my point a little here.
Running this command works:
prog.sh 0 Y DOWNLOAD PRINTER_TYPE=APPLE
Running the same command with double-quotes in it fails
prog.sh 0 Y DOWNLOAD PRINTER_TYPE="APPLE"
for some reason exec command can not handle double-quotes properly.
> I guess you are missing my point a little here.
Possibly!
>
> Running this command works:
> prog.sh 0 Y DOWNLOAD PRINTER_TYPE=APPLE
>
> Running the same command with double-quotes in it
> fails
> prog.sh 0 Y DOWNLOAD PRINTER_TYPE="APPLE"
>
> for some reason exec command can not handle
> double-quotes properly.
Using Linux, it works for me on String[] command = {"sh","-c","openssl genrsa -out \"rsapriv.pem\" 2048"};