> Runtime.getRuntime().exec("ls | grep");
>
> But how do I get the return stuff ?
Start by reading the API documentation for Runtime.exec(), and note
that there is a return value:
Process p = Runtime.exec(...);
Get the exit value from the Process:
p.exitValue();
However the example you've given will most definitely *not* work as
you expect because of the pipe character. Pipes are a shell feature,
but Runtime.exec() does not use a shell to run the command. If you
want to use pipes, redirection or other shell features you must run a
shell yourself. You also need to group the arguments correctly for the
shell, e.g.:
String[] cmd = { "/bin/sh", "-c", "ls | grep foo" };
Process p = Runtime.exec(cmd);
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
me2 - 05 Nov 2006 17:57 GMT
>> Runtime.getRuntime().exec("ls | grep");
>>
[quoted text clipped - 20 lines]
>
> /gordon
Excellent reply. Thanks ! Much appreciated.
Next question... is an exec call blocking ? Ie does the current thread
hold up until the command is done ? It seems to the way you use p to
access the reply like that.
Gordon Beaton - 05 Nov 2006 18:22 GMT
> Next question... is an exec call blocking ? Ie does the current
> thread hold up until the command is done ? It seems to the way you
> use p to access the reply like that.
No, Runtime.exec() returns after starting the child, which then runs
separate from the caller. Between calling exec() and p.exitValue() you
must read from (both!) stdout and stderr of the child until EOF.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e