这让我感到困惑。使用以下代码:
Process du = new Process();
string cmdPath = System.IO.Path.Combine(Environment.SystemDirectory, "du.exe");
Debug.WriteLine(cmdPath);
ProcessStartInfo info = new ProcessStartInfo(cmdPath);
info.CreateNoWindow = true;
info.Arguments = arguments;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
du.StartInfo = info;
du.EnableRaisingEvents = true;
du.OutputDataReceived += responseParser;
du.Start();
du.BeginOutputReadLine();
du.WaitForExit();
我运行代码后出现以下错误信息:
尽管cmdPath的输出值为未处理异常:System.ComponentModel.Win32Exception:系统找不到指定的文件
C:\Windows\system32\du.exe
!当我在命令提示符中输入cmdPath
的内容时,它会运行du.exe并给出用法信息。 如果我将命令路径替换为“du.exe”,并将du.exe放在工作目录中,则一切正常。但是我想引用系统位置中的du.exe。 那么,出了什么问题?据我所知,我有一个合法的文件说明符,但为什么Process.Start()
无法执行它?这段基本代码还执行了几个其他程序并获取其输出。其他程序都能正常工作,尽管du.exe与它们不同,因为它位于system32目录中。这是否与问题有关?谢谢。