[英]Error in Process.Start() – The System cannot find the file specified
[英]Process.Start(): The system cannot find the file specified, but my file path seems to be legit
這令人難以置信。 使用以下代碼:
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();
我跑了,我得到:
未處理的異常:System.ComponentModel.Win32Exception:系統找不到指定的文件
雖然cmdPath的輸出值是C:\\Windows\\system32\\du.exe
!
當然,如果我只是在命令提示符下鍵入cmdPath
的內容,它會運行du.exe並提供使用信息。
此外,如果我用“du.exe”替換命令路徑,並將du.exe放在工作目錄中,一切正常。 但我想引用系統位置中的那個。
那么發生了什么? 據我所知,我有一個合法的文件說明符,但為什么Process.Start()
執行它? 這個基本代碼也執行其他幾個程序並獲得它們的輸出。 其他都工作正常,雖然du.exe與它們不同,因為它位於system32目錄中。 這與它有關嗎?
謝謝
這取決於文件系統重定向器 。 您將在64位計算機上運行32位進程。 這意味着C:\\Windows\\system32
被透明地重定向到C:\\Windows\\SysWOW64
,我希望在那里找不到du.exe
。 如果您使用C:\\Windows\\Sysnative
那么您將能夠找到該文件。
但是,我懷疑您已將du.exe
添加到系統目錄,因為這不是標准的Windows組件。 你不應該這樣做。 我建議你把文件放在別處,因為你根本不應該寫在系統目錄中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.