Csung runs the. exe file in a single process and obtains the output.

Source: Internet
Author: User

Sometimes you need to run other programs in the program and obtain output results for further processing .. NET Framework has provided corresponding classes and methods, and we can easily achieve our goal.

The following example is used previously. It mainly uses the Process class and ProcessStartInfo class.

The main function of the Process class is to provide access to local and remote processes and enable you to start and stop local system processes.

The ProcessStartInfo class mainly serves to specify a group of values used to start a Process for the Process class.

 

Code 1 Process process = new Process ();
2 ProcessStartInfo startInfo = new ProcessStartInfo ("cmd.exe ");
3 startInfo. UseShellExecute = false;
4 process. StartInfo = startInfo;
5 process. StartInfo. RedirectStandardInput = true;
6 process. StartInfo. RedirectStandardOutput = true;
7 process. Start ();
8
9 process. StandardInput. WriteLine ("netstat-");
10 process. StandardInput. WriteLine ("exit ");
11
12 string netMessage = process. StandardOutput. ReadToEnd ();
13 process. WaitForExit ();
14 process. Close ();
15 return netMessage;

The above code is used to open a console in a new process, run the "netstat-an" command, and obtain the output result.

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.