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 );}}}