I have the following code.
ProcessStartInfo si = new ProcessStartInfo("cmd.exe");
si.RedirectStandardInput = true;
si.RedirectStandardOutput = true;
si.UseShellExecute = false;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
Process p = Process.Start(si);
p.StandardInput.Write("ipconfig");
p.StandardInput.Write("exit");
string consoleOutput = p.StandardOutput.ReadToEnd();
string dir="here";
The execution reaches “string consoleOutput” but never reaches “string dir” ie the code gets stuck on reading the StandardOutput. It is runnung from within a console application if this makes any difference.
You have to explicitly finish writing to the standard input by closing the stream. See Microsoft’s example.
In summary:
Edit: Tested in Visual Studio.
By the way, you want to use
WriteLine()instead ofWrite().