简体   繁体   English

Process.Start():系统找不到指定的文件,但我的文件路径似乎是合法的

[英]Process.Start(): The system cannot find the file specified, but my file path seems to be legit

This is boggling my mind. 这令人难以置信。 Using the following code: 使用以下代码:

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();

I run that, and I get: 我跑了,我得到:

Unhandled Exception: System.ComponentModel.Win32Exception: The system cannot find the file specified 未处理的异常:System.ComponentModel.Win32Exception:系统找不到指定的文件

though the output value of cmdPath is C:\\Windows\\system32\\du.exe ! 虽然cmdPath的输出值是C:\\Windows\\system32\\du.exe

and of course, if I just type the contents of cmdPath into a command prompt, it runs du.exe and gives me the usage info. 当然,如果我只是在命令提示符下键入cmdPath的内容,它会运行du.exe并提供使用信息。

Also, if I replace the command path with just "du.exe", and put the du.exe in the working directory, all works fine. 此外,如果我用“du.exe”替换命令路径,并将du.exe放在工作目录中,一切正常。 But I want to reference the one in the system location. 但我想引用系统位置中的那个。

So, what is going on? 那么发生了什么? As far as I can tell, I have a legitimate file specifier, but why won't Process.Start() execute it? 据我所知,我有一个合法的文件说明符,但为什么Process.Start()执行它? This basic code is also executing several other programs and getting their output. 这个基本代码也执行其他几个程序并获得它们的输出。 The others all work fine, though du.exe is different from them in that it's in the system32 directory. 其他都工作正常,虽然du.exe与它们不同,因为它位于system32目录中。 Does that have something to do with it? 这与它有关吗?

Thanks 谢谢

This is down to the file system redirector . 这取决于文件系统重定向器 You will be running a 32 bit process on a 64 bit machine. 您将在64位计算机上运行32位进程。 That means that C:\\Windows\\system32 is transparently redirected to C:\\Windows\\SysWOW64 and I expect that du.exe cannot be found there. 这意味着C:\\Windows\\system32被透明地重定向到C:\\Windows\\SysWOW64 ,我希望在那里找不到du.exe If you use C:\\Windows\\Sysnative instead then you will be able to locate the file. 如果您使用C:\\Windows\\Sysnative那么您将能够找到该文件。

However, I suspect that you have added du.exe to the system directory since this is not a standard Windows component. 但是,我怀疑您已将du.exe添加到系统目录,因为这不是标准的Windows组件。 You should not do that. 你不应该这样做。 I recommend you put the file somewhere else because you simply should not be writing in the system directory. 我建议你把文件放在别处,因为你根本不应该写在系统目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Process.Start()中的错误 - 系统找不到指定的文件 - Error in Process.Start() – The System cannot find the file specified Process.Start(…)引发“系统找不到指定的文件” - Process.Start(…) throws “The system cannot find the file specified” “系统找不到指定的文件”错误on process.Start(); - “The system cannot find the file specified” error on process.Start(); Process.Start() 中的错误——系统找不到指定的文件 - Error in Process.Start() -- The system cannot find the file specified system32应用程序的Process.Start - 系统无法找到指定的文件 - Process.Start for system32 applications - The System Cannot Find the File Specified Process.Start in C# The system cannot find the file specified error - Process.Start in C# The system cannot find the file specified error Process.Start in C# 系统找不到指定的文件错误使用变量名 - Process.Start in C# The system cannot find the file specified error using a variable name Process.Start("IIS Manager.lnk") 失败并显示“系统找不到指定的文件” - Process.Start("IIS Manager.lnk") fails with "The system cannot find the file specified" Process.Start dirquota.exe-系统找不到指定的文件 - Process.Start dirquota.exe - The system cannot find the file specified Process.Start找不到指定的文件,但是绝对存在-为什么? - Process.Start can not find file specified, but it is definitely there - why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM