Original article title: C # program a CMD command window executes multiple DOS commands
Original article Address: http://www.cnblogs.com/visibleisfalse/p/3578886.html
The following code has a modified, marked red code, which indicates that after executing a DOS command, wait for execution to complete.
Public voidDodos (stringCOMD1,stringCOMD2,stringcomd3) {Process P=NewProcess ();//Create a Process object Try{p.startinfo.filename="Cmd.exe";//set the command to be executed//startinfo.arguments = "/C" + command;//"/C" means to exit immediately after executing the command.P.startinfo.useshellexecute =false;//booting without using the system shellP.startinfo.redirectstandardinput =true;//can redirect inputP.startinfo.redirectstandardoutput =true; P.startinfo.redirectstandarderror=true; P.startinfo.createnowindow=true;//If a DOS window is displayed, True indicates hidden;P.start (); P.standardinput.writeline (COMD1); p.waitforexit (); //after each sentence executes and waits until execution endsP.standardinput.writeline (COMD2); p.waitforexit (); P.standardinput.writeline (COMD3); p.waitforexit (); } Catch(Exception) {}finally { if(P! =NULL) {p.close (); } }}
C #, a cmd command window executes multiple DOS commands (with modification, join execution wait)