/*************************************** ******************
* Function: Use the C # program to call the Windows Notepad program for editing.
* A text file named test.txt.
*
* In the entire program, system. Diagnostics. process. Start (Info)
* Is a statement.
* Simply execute an external program. You can use the following code:
* System. Diagnostics. process. Start (
* "External program name", "Startup parameter ");
*
**************************************** *****************/
1 using system;
2
3 class test
4 {
5 static void main ()
6 {
7
8 // declare a Program Information Class
9 system. Diagnostics. processstartinfo info = new system. Diagnostics. processstartinfo ();
10
11 // set the external program name
12 info. filename = "notepad.exe ";
13
14 // set the startup sequence of the program to test.txt
15 info. Arguments = "test.txt ";
16
17 // set the external program working directory to c :\
18 info. workingdirectory = "C :\\";
19
20 // declare a program class
21 system. Diagnostics. Process proc;
22
23 try
24 {
25 //
26 // start the external program
27 //
28 proc = system. Diagnostics. process. Start (Info );
29}
30 catch (system. componentmodel. win32exception E)
31 {
32 console. writeline ("the system cannot find the specified program file. \ R {0} ", e );
33 return;
34}
35
36 // print the start time of the external program
37 console. writeline ("Start Time of external program execution: {0}", Proc. starttime );
38
39 // wait 3 seconds
40 Proc. waitforexit (3000 );
41
42 // force terminate an external program if it has not ended
43 If (Proc. hasexited = false)
44 {
45 console. writeline ("the main program forcibly terminates the running of the external program! ");
46 Proc. Kill ();
47}
48 else
49 {
50 console. writeline ("the external program Exits normally! ");
51}
52 console. writeline ("End Time of the external program: {0}", Proc. exittime );
53 console. writeline ("returned value of an external program when it stops running: {0}", Proc. exitcode );
54}
55}