2009/04/07

Calling DOS command with parameters

I saw someone was asking about how to call DOS commands and how to pass the parameters. Here is the way to do it:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig.exe";
p.StartInfo.Arguments = @"/all";
p.Start();
p.WaitForExit();
string strResult = p.StandardOutput.ReadToEnd();

PS: If your command doesn't work when you change the parameters, try to comment out the
p.WaitForExit();

No comments:

Post a Comment