Run Dos Command by C# (2010-02-09)
public String RunCMD(String cmd)
{
System.Diagnostics.ProcessStartInfo sdpsinfo = new System.Diagnostics.ProcessStartInfo
(cmd);
// The following commands are needed to
//redirect the standard output.
// This means that it will //be redirected to the
// Process.StandardOutput StreamReader
// u can try other console applications
//such as arp.exe, etc
sdpsinfo.RedirectStandardOutput = true;
// redirecting the standard output
sdpsinfo.UseShellExecute = false;
// without that console shell window
sdpsinfo.CreateNoWindow = true;
// Now we create a process,
//assign its ProcessStartInfo and start it
System.Diagnostics.Process p =
new System.Diagnostics.Process();
p.StartInfo = sdpsinfo;
p.Start();
// well, we should check the return value here...
// capturing the output into a string variable...
string res = p.StandardOutput.ReadToEnd();
// do whatever u want to do with that output
return res;
}
|