Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pipe an OutputStream and InputStream to console?

When running a process, how do I pipe it's output to System.out and it's input to System.in:

Process p = Runtime.getRuntime().exec("cubc.exe");
// do something with p.getOutputStream())

EDIT: I think I explained this wrong; I don't want to input to the program, I want the user to input to the program, and I don't want to read the output, I want the user to read the output.

like image 363
personak Avatar asked Jan 19 '23 05:01

personak


1 Answers

Using IOUtils class from Apache Commons IO:

Process p = Runtime.getRuntime().exec("cubc.exe");
IOUtils.copy(p.getInputStream(), System.out);
like image 127
Tomasz Nurkiewicz Avatar answered Jan 31 '23 01:01

Tomasz Nurkiewicz