Question

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.

Was it helpful?

Solution

Check http://www.codeproject.com/cs/library/CommandLineHelper.asp

[marc_s] that URL results in a 404-page not found.

The right URL most likely is: http://www.codeproject.com/KB/string/CommandLineHelper.aspx

OTHER TIPS

I think you cant. If you show the console command Prompt, you wont be able to read the output. I think you need to draw your own command prompt if your reading the output of a process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top