How do you connect OutputStream and InputStream to the console?

When the process starts, how can I transfer its output to System.out and it is entered in System.in :

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

EDIT: I think I explained it wrong; I do not want to enter the program, I want the user to enter the program, and I do not want to read the output, I want the user to read the result.

+4
source share
3 answers

Using the IOUtils class from Apache Commons IO :

 Process p = Runtime.getRuntime().exec("cubc.exe"); IOUtils.copy(p.getInputStream(), System.out); 
+10
source

You can get input like this:

 Scanner scan = new Scanner(p.getInputStream()); 

As for the output stream, you can capture it in the same way and print it using the System.out methods . * :

 OutputStream os = p.getOutputStream(); 
+2
source

You cannot do this with Java as such. However, you can create your own process and use PipedOutputStream to catch the output and then write it to System.out.println. Another, then, I do not think there is another way.

-3
source

All Articles