I am trying to interact with the windows command prompt from code. My goal is to display the prompt, put in some command, display the output, and repeat. But can't seem to get the first three working at the same time.
private void button2_Click(object sender, EventArgs e)
{
Process proc = new Process();
proc.StartInfo.FileName = "cmd";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardInput = true;
proc.Start();
StreamReader k = new StreamReader(proc.StandardOutput.BaseStream);
textBox2.Text = k.ReadToEnd();
}
The above code just hangs. If I don't set RedirectStandardInput, then I can display the entire prompt. And if I close the writer for StandardInput I can get a command to run, but without seeing the prompt, or being able to repeat it. So how can I get the prompt to show, run a command, and show the output ... repeatedly?
I am hoping to reproduce the command line behavior of Console2 but I am a little overwhelmed by it's source code.