On May 5, 12:33 pm, Marteno Rodia <marteno_ro...@o2.pl> wrote:
....
> After reading the documentation and Internet resources, I came to
> conclusion that I should use Runtime.exec() and then
that would be one way of doing it
> Process.getInputStream() to capture the output stream! (the output of
> the subprogram is the input of the superprogram).
No, that is not mandatory at all.
If you want to go the Runtime.exec() route, then I'd
simply give you the following advice that shall save
you a lot of "stream processing" / "stream consuming"
headaches:
wrap the call to your Java program inside a script
that suppresses all outputs from your Java program.
Instead of doing Runtime.exec( "Java prog" )
you do Runtime.exec ( "script that wraps Java prog" )
For example a Bash shell script (for, say, Linux and OS X),
doing that could look like:
#!/bin/bash
#
# Shell script that suppresses output
#
java -jar myprog.jar >/dev/null 2>/dev/null
Under Windows a simple @echo off at the beginning
of a batch script would do.
If you do actually care about the output, redirect
to a file instead of /dev/null and parse that file.
That shall be incredibly easier than trying to
consume the streams yourself from your "outter"
Java program.
Especially if, in your case, you really don't need
these outputs. Simply Runtime.exec the wrapper
script without waiting.
This is such a common concern that there ought to be some
helper methods/libs (maybe in Jakarta commons?) mimicking
the way C# does it:
process.StartInfo.Arguments = "> NULL";
And poof, no more outputs
P.S: don't try to suppress the output directly
from Runtime.exec(...) for the redirection symbols
don't work as you'd think.