[英]Process.Start in C# The system cannot find the file specified error using a variable name
I am launching process in c# from parameters that are passed to the application.我正在从传递给应用程序的参数在 c# 中启动进程。
The parameters are placed into variables which are then passed to the process start.参数被放入变量中,然后传递给流程开始。
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = FileName;
startInfo.WorkingDirectory = Path.GetDirectoryName(FileName);
startInfo.Arguments = Arguments;
startInfo.ErrorDialog = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
Process proc = Process.Start(startInfo);
I have tried using single slashes and double slashes in the paths but still get the same error.我曾尝试在路径中使用单斜杠和双斜杠,但仍然出现相同的错误。 This is a log file (ignore the dates and double equals) the paths are what the variable contained each test.
这是一个日志文件(忽略日期和双等号)路径是每个测试包含的变量。 I tried double slashes and single slashes.
我试过双斜线和单斜线。
attempt 1
C:\\Program Files\\Internet Explorer
C:\\Program Files\\Internet Explorer\\iexplore.exe
attempt 2
C:\Program Files\Internet Explorer
C:\Program Files\Internet Explorer\iexplore.exe
I also tried adding a "@" in front of the FileName variable hoping that might help (didn't) Anyone have any ideas as to why this won't see the file?我还尝试在 FileName 变量前面添加一个“@”,希望这可能会有所帮助(没有)任何人对为什么看不到文件有任何想法?
These parameters were being passed through a protocol handler (HTML page) and spaces in the paths were replaced with which was then removed and replaced with spaces in the application.这些参数通过协议处理程序(HTML 页面)传递,路径中的空格被替换,然后被删除并替换为应用程序中的空格。 For some reason the replacement didn't exactly work even though the filename looked correct in the application the file was never seen.
出于某种原因,即使文件名在应用程序中看起来正确但从未见过该文件,替换也不能完全起作用。 I removed the and replaced with the spaces in the HTML that calls the protocol handler (they were not needed) and now the files are seen correctly.
我删除了 并替换为 HTML 中调用协议处理程序的空格(不需要它们),现在可以正确看到文件。 Not sure why they were like that to begin with unless the command line script in the registry did not have quotes around the %1 parameter
不知道为什么他们会这样开始,除非注册表中的命令行脚本在 %1 参数周围没有引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.