io - Starting a process with inherited stdin/stdout/stderr in Java 6 -


if start process via java's processbuilder class, have full access process's standard in, standard out, , standard error streams java inputstreams , outputstreams. however, can't find way seamlessly connect streams system.in, system.out, , system.err.

it's possible use redirecterrorstream() single inputstream contains subprocess's standard out , standard error, , loop through , send through standard out—but can't find way , let user type process, or if used c system() call.

this appears possible in java se 7 when comes out—i'm wondering if there's workaround now. bonus points if result of isatty() in child process carries through redirection.

you need copy process out, err, , input streams system versions. easiest way using ioutils class commons io package. copy method looks need. copy method invocations need in separate threads.

here basic code:

// assume have processbuilder configured , ready go final process process = processbuilder.start(); new thread(new runnable() {public void run() {   ioutils.copy(process.getoutputstream(), system.out); } } ).start(); new thread(new runnable() {public void run() {   ioutils.copy(process.geterrorstream(), system.err); } } ).start(); new thread(new runnable() {public void run() {   ioutils.copy(system.in, process.getinputstream()); } } ).start(); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -