Implement the method that calls cmd under asp.net of c

  • 2020-05-16 06:49:25
  • OfStack

The following example USES the namespace System.Diagnostics;
The System.Diagnostics namespace contains classes 1 that can interact with system process event logs and performance counters to help diagnose and debug applications such as the Debug class to help debug code. The Process class can control process access and the Trace class can track code execution
Process is used to operate local or remote process call access. With Process, it is easy to start or stop external processes in a managed environment.
 
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(); 
} 

} 
} 

The corresponding FileName and Arguments properties must be set
Take ping for example
The code is as follows:
 
string hostname = "http://www.baidu.com"; // Or here is 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()); 

There are many other commands that you can call that you can explore yourself

Related articles: