Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("md");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
string a = p.StandardOutput.ReadToEnd();
p.Close();
在这里我输入了一个md命令,因为这个命令是无效的。所以返回给CMD“命令语法不正确”。
那么我如何才能得到“命令语法不正确”这个字符串呢?
请大家帮帮忙~~
ShellControl - A console emulation control
http://www.codeproject.com/KB/miscctrl/shellcontrol.aspx