C#中获取CMD命令返回的结果,总是获取不到想要的。。
爱笑的阳光 2015-05-04 08:55:10 这个是获取到的字符串结果:
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
E:\代码\参考\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug>ipconfig\
E:\代码\参考\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug>exit
代码:
Cmd c = new Cmd();
c.RunCmd(@"ipconfig\");
public string RunCmd(string cmd)
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.StandardInput.WriteLine(cmd);
proc.StandardInput.WriteLine("exit");
string outStr = proc.StandardOutput.ReadToEnd();
proc.Close();
return outStr;
}
大神帮忙看看是不是那地方存在问题,小弟拜谢了!!!