C # call input cmd command and export the result to txtbox

Do a little tool, enter the cmd command in the text box txtbox, after running, the result is displayed in another txtbox, the source code is as follows:

 private  void button1_Click ( object sender, EventArgs e) 
        { 
            Process proc = new Process (); 
            proc.StartInfo.CreateNoWindow = true ; 
            proc.StartInfo.FileName = " cmd.exe " ; // Create and execute cmd 
            proc.StartInfo.UseShellExecute = false ; // Start the process without enabling the shell 
            proc.StartInfo.RedirectStandardError = true ; // Redirect error output 
            proc.StartInfo.RedirectStandardInput = true ;// Redirect input 
            proc.StartInfo.RedirectStandardOutput = true ; // Redirect standard output 
            proc.Start (); // Start execution 
            proc.StandardInput.WriteLine (textBox1.Text); // Run the command 
            proc in the text box . StandardInput.WriteLine ( " exit " );
             string outStr = proc.StandardOutput.ReadToEnd (); 
            textBox2.Text = outStr; // Output execution result 
            proc.Close (); // Close end 
        }

The execution result is shown in the figure below:

You can also execute two commands at the same time, as shown in the following figure:

Guess you like

Origin www.cnblogs.com/suyun0702/p/12752049.html