我正在运行这个
string path = string.Format(@"\\{0}\c$\Windows\CCM\Logs", computerName);
Process process = Process.Start(new ProcessStartInfo()
{
FileName = "cmd.exe",
Arguments = string.Format(@"net use {0} && dir {0}", path),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
});
string result = process.StandardOutput.ReadToEnd() + " " + process.StandardError.ReadToEnd();
process.WaitForExit();
Console.WriteLine(result);
但是没有任何内容被写入控制台。我究竟做错了什么?我已经浏览了可能与此相关的所有其他 SO 线程并进行了大量谷歌搜索,但我无法让它工作。
最佳答案
cmd.exe
需要使用/C
选项,否则子进程不会退出。
/C Carries out the command specified by string and then terminates
(在您的命令提示符中键入 cmd/?
以获取更多信息)
关于c# - 无法从 cmd 获取输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22372485/