I am trying to build a wrapper around a console application using StandardInput and StandardOutput. I get stuck when a console application asks for input, such as a password.
I would like to read from StandardOutput, ask the user to use the read text, and write the user's input back to the console application using standard input. It seems simple enough, here is what I have at the moment:
Process process = new Process() { StartInfo = { FileName = "bin\\vpnc.exe", Arguments = "--no-detach --debug 0", CreateNoWindow = true, UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, } }; process.OutputDataReceived += (s, args) => { textBlock1.Dispatcher.Invoke(new Action(() => { textBlock1.Text += args.Data; })); }; process.Start(); process.BeginOutputReadLine();
The problem is that BeginOutputReadLine() does just that ... waiting for the end of the line. In this case, it just sits, sits and sits, because there is no line to read ... the console application wrote out the text without ending the line and waits for input. By the way, when I manually kill the process, the event fires, and I get the text.
Is there any way to say that the process is expecting StandardInput? Or am I missing a very obvious way to achieve my goal?
source share