C # Learning (4)-using the shell to invoke an external EXE app

Source: Internet
Author: User

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

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.