I am calling few perl routines from my Java program (in an Unix environment) using Runtime process call. While most get executed normally, I am facing problem with routines that get parameters as output from other routine i.e. routines that use Piping, ex:
When run directly from command line it works well. But when called through my program only the routine1 gets exceuted printing its output at command line, the second routine doesn't get the output from first and does not execute. I am not aware of and cannot change the perl routines.
How do you call piped Perl routines using Runtime process call?
Thanks for your time, [ May 12, 2005: Message edited by: Debashish Chakrabarty ]
Implementing the piping yourself would be interesting. Start two processes, start a thread that reads the stdout of the first and writes to the stdin of the second. It would sure be nicer if you could get the piping going outside of Java, tho.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I finally found the solution here. As the article says, Runtime.exec invokes actual executable binary programs. Syntax such as pipe and > are part of a particular command processor, and are only understood by that processor. So the command preceding the pipe is executed, but the rest of the shell command is not.