I have been working with processes (using the Process and ProcessStartInfo) with C# quite some time. Now, there is only one question that really bothered me and still haven't managed to find a way to work it out.
The StandardOutput will hang when the application is "waiting" for some input.
Which means, if you are using ReadToEnd it will never return (as the actual input window is invisible).
Now, this creates a problem when I'm using the StandardInput to provide the input. For example:
- Starting the process with C#
- Entering a command using StandardInput.
- Start reading the stream for the ouptut.
- Running another one based on the last output.
Now this is the problem: I can't tell whether the process is waiting for input or it's still generating one, as my process "gets" stuck to read from the StandardOutput (it's done on the same thread).
I need to read the output after my command ran, run some algorithms and then run another command based on the previous command output.
Is there is any way of detecting if the process running finished loading my command and waiting for new input? Just like the cmd does?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…