Implicit CMD command line window in C #

Source: Internet
Author: User


The CMD command line of MS is an important operation interface. Some functions that are not easy to complete in C # can be easily implemented by using a few simple commands in CMD, if you can complete the CMD Window Function in C #, it will make our program much easier.

The following describes how to use the cmd.exe program in the C program without displaying the command line window interface.

As follows:

System. Diagnosties. Process p = new System. Diagnosties. Process ();
P. StartInfo. FileName = "cmd.exe"; // name of the program to be executed
P. StartInfo. UseShellExecute = false;
P. StartInfo. RedirectStanderInput = true; // the input information from the caller may be accepted.
P. StartInfo. RedirectStanderOutput = true; // the output information is obtained by the calling program.
P. StartInfo. CreateNoWindow = true; // The program window is not displayed.
P. Start (); // Start the program
// Send the input information to the CMD window:
P. StanderInput. WriteLine ("shutdown-r t 10"); // restart after 10 seconds (C # may be hard to do)
// Obtain the output information of the CMD window:
String sOutput = p. StandardOutput. ReadToEnd (); with the following code, you can operate CMD without knowing it. In short, the Process class is a very useful class, it is very convenient to use third-party programs to expand the C # function.

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.