C # Start an external program

Source: Internet
Author: User

Start an external program:

Using system; using system. collections. generic; using system. LINQ; using system. text;/* create a process and input the required parameters * or start an external program for the process, and pass in the parameter * Waiting to exit or force close */namespace consoleapplication1 {class program {static void main (string [] ARGs) {////////// declare a program information class and specify the parameter information of the startup process system. diagnostics. processstartinfo info = new system. diagnostics. processstartinfo (); // set the external program name info. filename = "notepad.exe"; // sets the startup parameters of an external program (command line Test.txt info. arguments = "test.txt"; // set the external program working directory to c: \ info. workingdirectory = "C: \"; // declare a program class, that is, to create a process system. diagnostics. process proc; try {// start external program // proc = system. diagnostics. process. start (Info);} catch (system. componentmodel. win32exception e) {console. writeline ("the system cannot find the specified program file. \ R {0} ", e); return;} // print the start time of the external program console. writeline ("external program start execution time: {0}", Proc. starttime); // wait 3 seconds for Proc. waitforexit (3000); // forcibly terminate if (Proc. hasexited = false) {console. writeline ("the external program is forcibly terminated by the main program! "); Proc. Kill () ;}else {console. writeline (" exited normally by external programs! ");} Console. writeline ("external program end run time: {0}", Proc. exittime); console. writeline ("returned value when the external program stops running: {0}", Proc. exitcode );}}}

 

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.