我需要在我的项目中使用命令提示符。一切正常,但输出不是我想要的。如果我这样做:C#命令提示符输出
ProcessStartInfo info = new ProcessStartInfo("cmd","/c dir c:\\test");
info.RedirectStandardOutput = true;
info.RedirectStandardInput = true;
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process p = new Process();
p.StartInfo = info;
p.Start();
string iii = p.StandardOutput.ReadToEnd();
textBox1.Text = iii;
结果是好的。完全如我所愿。但我还需要发送更多命令。所以我这样做:
ProcessStartInfo info = new ProcessStartInfo("cmd");
info.RedirectStandardOutput = true;
info.RedirectStandardInput = true;
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process p = new Process();
p.StartInfo = info;
p.Start();
StreamWriter write = p.StandardInput;
write.WriteLine("dir c:\\test");
write.Close();
string iii = p.StandardOutput.ReadToEnd();
textBox1.Text = iii;
但结果是不像以前。它给出了cmd中的路径和所有内容,这是我不想要的。我只需要命令提示符的结果,而不需要其他东西。希望有人能帮忙。感谢您阅读我的问题。
嗯,我假设你指的是“dir c:\\ test”,这很容易解释:你自己写出来。像以前一样通过/ c传递。 – JerKimball
感谢您的回复我照你说的做了,但有了这个空白输出.. – user1965804