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 certainly make ourProgramEase of use.

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 "; // Program name to be executed P. startinfo. useshellexecute = False ; P. startinfo. redirectstanderinput = True ; // May accept input from the caller P. startinfo. redirectstanderoutput = True ;// The caller obtains the output information. P. startinfo. createnowindow = True ; // Do not display the program window 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 ();
 
BelowCodeThen 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.
 
 
 
Conclusion

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.