C #, a cmd command window executes multiple DOS commands (with modification, join execution wait)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.