PROCESS p = new process (); p. startinfo. filename = "cmd.exe"; // name of the program to be executed p. startinfo. useshellexecute = false; p. startinfo. redirectstandardinput = true; // the input information from the caller may be accepted. startinfo. redirectstandardoutput = true; // get the output information by the calling program p. startinfo. createnowindow = true; // do not display the program window p. start (); // start the program // send the input information to the CMD window: P. standardinput. writeline ("dir"); // obtain the output information of the CMD window: streamreader sr = P. standardoutput; string soutput = sr. readline ();// The following two sentences are crucial. If this parameter is not set, the system will crash because the stream will still receive a read row after reading the last row. Because there is no data for the stream to read, it will always wait.Threads. Sleep (5000); p. Kill (); While (soutput! = NULL) {This. textbox1.text + = soutput + "\ r \ n"; if (! Sr. endofstream) soutput = Sr. Readline (); else soutput = NULL;} Sr. Close (); p. Close ();
The above are just some simple problems I encountered in the project. They are published for your reference.