First create a Windows Forms program, where you add a button, and a textbox
Next we'll first invoke the HelloWorld we wrote before in the command prompt.
C:\Users\gao\Desktop\Hello.exe represents my hello where the app is generated, followed by the two strings that represent the two arguments that hello will use, and then enter both to get a result
Three next, use the button to output the Hello.exe run results to a TextBox
Double-click the button to add code
private void Button1_Click (object sender, EventArgs e) { Process process = new process (); Process. Startinfo.filename = "cmd.exe"; Process. Startinfo.useshellexecute = false; Process. Startinfo.redirectstandardinput = true; Process. Startinfo.redirectstandardoutput = true; Process. Startinfo.redirectstandarderror = true; Process. Startinfo.createnowindow = true; Process. Start (); String str = @ "C:\Users\gao\Desktop\Hello.exe" + "Fengye C #"; Process. Standardinput.writeline (str); Process. Standardinput.writeline ("Exit"); String sh = process. Standardoutput.readtoend (); Process. Close (); This.textBox1.Text = sh; }
The results of the operation are as follows:
author--Peak Ye
C # Learning (4)-using the shell to invoke an external EXE app