Runtime.exec help please

I am trying to use Runtime.exec to run a command and pass it a parameter.

I need it to preserve the spaces in the parameter but cannot get it to work.

E.g

My code says

String cmd = "sh1 xxxx1234";

Process child = Runtime.getRuntime().exec(cmd);

the sh1 bash shell says

echo '$@' = $@

echo '$1' = $1

echo '$2' = $2

When I run it it displays

$@ = xxxx 1234

$1 = xxxx

$2 = 1234

I want it to pass the code "as is" so as one parameter

So it would display

$@ = xxxx1234

$1 = xxxx1234

$2 =

I could even cope with

$@ = xxxx1234

$1 = xxxx

$2 = 1234

I have tried different variation of single and double quotes without any

success.

--

Steve

[801 byte] By [steve_rainbirda] at [2007-11-27 11:41:59]
# 1

ProcessBuilder seems to be the solution .

String cmd = "sh1";

String arg = "xxxx1234";

Process child = new ProcessBuilder(cmd,arg).start();

$@ = "xxxx1234"

$1 = "xxxx1234"

$2 =

steve_rainbirda at 2007-7-29 17:41:26 > top of Java-index,Java Essentials,Java Programming...