Implementing the method of calling Cmd under ASP.net (C #)-Practical Tips

Source: Internet
Author: User
The following ping is used as an example to use the namespace System.Diagnostics;
The System.Diagnostics namespace contains classes that can interact with system process event logs and performance counters to help diagnose and debug applications such as the Debug class used to help group debug code process classes to control processes access Trace class is able to track code execution
Processes are used to manipulate local or remote process access through the process can be easy to operate in a managed environment to start or stop an external process.
Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Diagnostics;
Namespace Testequal
{
Class Program
{
static void Main (string[] args)
{
Process myprocess = new process ();
MyProcess.StartInfo.FileName = "Iexplore.exe";
myProcess.StartInfo.Arguments = "http://www.baidu.com";
Myprocess.start ();
}

}
}

appropriate filename and arguments properties must be set
Let's take ping as an example
The code is as follows:
Copy Code code as follows:

string hostname = "http://www.baidu.com"; Or here is the IP and so on;
Process prc=new process ();
Prc. Startinfo.filename= "cmd.exe";
Prc. Startinfo.useshellexecute=false;
Prc. Startinfo.redirectstandardinput = true;
Prc. Startinfo.redirectstandardoutput = true;
Prc. Startinfo.redirectstandarderror = true;
Prc. Startinfo.createnowindow = false;
Prc. Start ();
Prc. Standardinput.writeline ("ping" + hostname);
Prc. Standardinput.close ();
Response.Write (PRC. Standardoutput.readtoend ());

Here you can also invoke many commands that you can study under

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.