Using the java exec() you cannot re-direct stdio as you can from the command line. The command line interpreter (shell) handles I/O redirection.
Using the Process object in Java, you need to handle redirection yourself. Here is one possible implementation:
Charles Hargrave wrote:At the risk of asking a silly question, is there any flow-print command line option for specifying an input file? Is it really required that you use the redirect?
If you have to pipe the file content into the command, there's probably a Java class that can handle that (never used it myself though).
I still think the easiest option would be to put the UNIX commands inside a UNIX shell script and have it accept a parameter for the input file's name (to be used in the UNIX command).
Oh well, it's late. If I think of anything else, I'll post again.
CNH
uniojn qoifazy wrote:
hi Charles Hargrave ,
it's need to use the redirect (<) to input file ,
and
it's work in java , but when i add "-f 5" it's failed ,
so , i think Java class that can handle redirect (<) , but i don't know why can't add more parameter (-f 5 ) ??
Charles Hargrave wrote:
uniojn qoifazy wrote:
hi Charles Hargrave ,
it's need to use the redirect (<) to input file ,
and
it's work in java , but when i add "-f 5" it's failed ,
so , i think Java class that can handle redirect (<) , but i don't know why can't add more parameter (-f 5 ) ??
I'm guessing that the redirect into the '-f 5' is treated differently through Java.
Jeff Verdegan wrote:
No.
We're not redirecting into -f 5. Those args are completely unrelated to the redirection. We're redirecting our input to come from the file specified by the "path" variable.
Java doesn't know or care anything about those args or the redirection. It just passes that all on to the /bin/sh command.
The structure looks correct, and since my similar /bin/ls command worked fine, and since his command works find without the -f 5, I have to guess that the -f 5 is either invalid to start with (hence my suggestion to try it directly on the command line) or else using -f 5 produces enough output on stdout or stderr to make it block.
uniojn qoifazy wrote:
so , i think the problem is like you said , generates a lot of screen output, it can fill up the the stderr and stdout streams and cause the process to lock up.
am i wrong ? do you have any idea to solve the problem ?
Jeff Verdegan wrote:
uniojn qoifazy wrote:
so , i think the problem is like you said , generates a lot of screen output, it can fill up the the stderr and stdout streams and cause the process to lock up.
am i wrong ? do you have any idea to solve the problem ?
As I already stated, try this: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Charles Hargrave wrote:If you don't want to save the output to a file, [...] 'NUL' in Windows
With all of this detail, you should be able to fix your code.