I posted a question sometime ago, but didnt get an answer hence am posting my core confusion.
I wonder Runtime.exec() can deal with user interaction in subprocess. For example, program A calls program B through Runtime.exec(). Program B gives some output and receives standard input. I understand how B's output is redirected to A, but I have no idea how B's standard input(terminal input) can be handled. When I tried this type of program, I found out two processes just wait(maybe blocked) forever.
Well I assume your program B is trying to read user input from the standard input? If so, the problem is that program B's stdin is also hooked up to A (the program that called B with Runtime.exec().) A can get ahold of B's stdin by invoking Process.getOutputStream(). Can you perhaps let A grab input from the user and then pass it to B?
Thanks for the input. I did try this but the process behaves a little strangely than I expected or probably I am making a mistake somewhere. Here's the piece of code which does this.
InputStream prin = process.getInputStream(); BufferedReader bin = new BufferedReader(new InputStreamReader(prin)); String temp = bin.readLine(); System.out.println("the process output" + temp); System.out.println("its trying to hook the input for B from A "); OutputStream prout = process.getOutputStream(); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = br.readLine(); System.out.println("taken input "); byte[] sb = s.getBytes(); prout.write(sb); prout.flush();
this code is put in a loop till process completes execution.
While executing this code I found out that the program executing this code just blocks.
Hope to get some input from you again. Thanks! Aarti.