C # example of calling the Exe program,

Source: Internet
Author: User

C # example of calling the Exe program,

When writing a program, you will often use calling executable programs. This article will briefly introduce how C # Calls exe. In C #, Process operations are performed through the Process class. The Process class is in the System. Diagnostics package.

Example 1
Using System. Diagnostics; Process p = Process. Start ("notepad.exe"); p. WaitForExit (); // key. It can be executed only after the external program exits.

 

 

The above code can call the Notepad program. Note that if you do not call the system program, you must enter the full path.

Example 2

When you need to call the cmd program, the above call method will pop up a nasty black window. If you want to cancel the configuration, You need to perform more detailed settings.

The StartInfo attribute of the Process class contains some Process startup information.

FileName executable program file name

The Arguments program parameter, which has been entered as a string
Does CreateNoWindow not need to be created?
Whether UseShellExecute requires a system shell call program

These parameters can be used to remove unwanted black screens.

System. diagnostics. process exep = new System. diagnostics. process (); exep. startInfo. fileName = binStr; exep. startInfo. arguments = reverse STR; exep. startInfo. createNoWindow = true; exep. startInfo. useShellExecute = false; exep. start (); exep. waitForExit (); // key. It can be executed only after the external program exits.

Or

System. diagnostics. process exep = new System. diagnostics. process (); System. diagnostics. processStartInfo startInfo = new System. diagnostics. processStartInfo (); startInfo. fileName = binStr; startInfo. arguments = shortstr; startInfo. createNoWindow = true; startInfo. useShellExecute = false; exep. start (startInfo); exep. waitForExit (); // key. It can be executed only after the external program exits.

 

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.