Home > Back-end >  GetInputstream and getOutputstream blocking problem
GetInputstream and getOutputstream blocking problem

Time:09-22

I use the ProcessBuilder running a program that both output and input (after the program to print output, input), then I want to use getInputstream programs run print output, input by getOutputstream (here I use the multithreading), results getInputstream obstruction in the read there, if not for input, just not print the contents of the
But the program logic is clearly print output, and in the CMD Windows to run the program is normal, why here with the ProcessBuilder run can only output first? I tried to modify the sequence of statements InputStream and OutputStream, still doesn't work, please help analysis.
 InputStream InputStream=process. GetInputStream (); 
Thread=new thread (new Runnable () {
@ Override
Public void the run () {
Try {
Int it=0;
Do {
int count=0;
While (count==0) {
Count=inputStream. Available ();
}
It=inputStream. Read ();
The d (" DDD ", "read=" + it);
} while (it!=1);
} the catch (IOException e) {
e.printStackTrace();
}
}
});
Thread. The start ();
OutputStream OS=process. GetOutputStream ();
BufferedWriter=new bufferedWriter (new OutputStreamWriter (OS));
Try {
BufferedWriter. Write (" 5 \ n ");//only for input, to perform the read above, what reason be?
} the catch (IOException e) {
e.printStackTrace();
}

CodePudding user response:

Why didn't respond
  • Related