How to run piped Unix commands

Hi,

I'm trying to run piped Unix commands using Runtime.getRuntime().exec(...) but apparently the pipe symbol ("|") doesn't seem to work...

Here is basically what I'm trying to do: running "command1 | command2" where both "command1" and "command2" have dynamic values. I could create a shell script and execute it through Java but there has to be a cleaner way...

Can anyone help me with this?

Thanks,

--

Thierry

[472 byte] By [kobaia27] at [2007-9-30 2:55:32]
# 1
My guess is you have to run a shell, and pass the command line to the shell. Here's a couple samples:sh -c 'echo somestuff | grep stuff'sh -c 'echo somestuff | grep staff'
inco5 at 2007-6-29 10:53:55 > top of Java-index,Administration Tools,Sun Connection...
# 2
Thanks, but I tried this as well and it still didn't work :(
kobaia27 at 2007-6-29 10:53:55 > top of Java-index,Administration Tools,Sun Connection...
# 3

The | symbol for a pipe is understood by a shell, so it was right to point to this direction.

If you still have a problem, that might be because of another reason. What did happen, how exactly did it not work? Did you take care of the stdin and stdout channels of the launched process?

BIJ001 at 2007-6-29 10:53:55 > top of Java-index,Administration Tools,Sun Connection...
# 4
Do you exec something like this?String[] { "sh" , "-c" , "myprog1 | myprog2" }
BIJ001 at 2007-6-29 10:53:55 > top of Java-index,Administration Tools,Sun Connection...
# 5
Thanks it seems to be working with the String[].
kobaia27 at 2007-6-29 10:53:55 > top of Java-index,Administration Tools,Sun Connection...