I am executing a process using the Process class. Going through the error stream seems to be necessary to execute the process successfully. Why is going through the error stream necessary for the process to run correctly? Is there something I am doing wrong?
Process wkstdin = Runtime.getRuntime().exec(command);
BufferedWriter wkstdin_writer = new BufferedWriter(
new OutputStreamWriter(wkstdin.getOutputStream()));
//write data
Necessary Part of the Code:
BufferedReader input = new BufferedReader(new InputStreamReader(
wkstdin.getErrorStream()));
String ch;
while ((ch = input.readLine()) != null)
{
System.out.println(ch);
}
When the process writes to stderr the output goes to a fixed-size buffer. If the buffer fills up then the process blocks until there is room for the remaining output in the buffer. So if the buffer doesn't empty then the process will hang.
Also if something goes wrong with the process you'd like to know about it, the error stream may contain actual useful information.
Some suggestions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With