> > Hello
> > I am looking for class which will encapsulate a process(with no GUI)
[quoted text clipped - 10 lines]
>
> - Show quoted text -
Do you know what system("any executable") function does in C?
It simply executes command passed to it.
No need to take any OutputStream and InputStream.
I want such a thing in Java.
I want to be able to execute a process and OutputStream should be
Stdout & InputStream should be stdin.
You know how to do it???
Gordon Beaton - 07 Feb 2007 18:09 GMT
> Do you know what system("any executable") function does in C? It
> simply executes command passed to it. No need to take any
> OutputStream and InputStream. I want such a thing in Java. I want to
> be able to execute a process and OutputStream should be Stdout &
> InputStream should be stdin.
Java's mechanisms for executing child processes (Runtime.exec() and
java.lang.ProcessBuilder) do not let the child share the same input
and output streams as the Java application itself.
The child's streams are always connected through streams available
through a Process object. As such, these mechanisms more closely
resemble p2open() (or popen()) than system().
/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
Chris Uppal - 07 Feb 2007 19:00 GMT
> Do you know what system("any executable") function does in C?
> It simply executes command passed to it.
> No need to take any OutputStream and InputStream.
> I want such a thing in Java.
> I want to be able to execute a process and OutputStream should be
> Stdout & InputStream should be stdin.
As far as I know (and I'd be very pleased to be shown I'm wrong) there is no
way
(short of using JNI) that you can execute a external program from Java and have
it inherit its stdin/stdout/stderr from the parent process.
The best I can think of is to attach threads to each of the external process's
streams which forward to/from the corresponding System.out/err/in. And that,
unfortunately, is not quite the same...
-- chris