When the process starts, how can I transfer its output to System.out and it is entered in System.in :
System.out
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.
Using the IOUtils class from Apache Commons IO :
IOUtils
Process p = Runtime.getRuntime().exec("cubc.exe"); IOUtils.copy(p.getInputStream(), System.out);
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();
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.