系统找不到指定的文件.process.Start()出错
本文关键字:Start 出错 process 文件 找不到 系统 | 更新日期: 2023-09-27 18:01:51
我试图得到的过程响应作为一个字符串,所以我可以使用它在不同的地方在我的代码,这是解决方案,我有到目前为止:
const string ex1 = @"C:'Projects'MyProgram.exe ";
const string ex2 = @"C:'Projects'ProgramXmlConfig.xml";
Process process = new Process();
process.StartInfo.WorkingDirectory = @"C:'Projects";
process.StartInfo.FileName = "MyProgram.exe ";
process.StartInfo.Arguments = ex2;
process.StartInfo.Password = new System.Security.SecureString();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
try
{
process.Start();
StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();
}
catch (Exception exception)
{
AddComment(exception.ToString());
}
但是当我运行这个时,我得到:
"The system cannot find the file specified" error in process.Start(); without process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true;
代码运行良好,但它只是打开控制台窗口,所有的进程响应都在那里,所以我不能使用它作为字符串。
有没有人知道为什么我得到这个错误,或者可能是一个不同的解决方案,我的问题?
我怀疑问题是您指定的文件名相对于您的工作目录,并且您期望Process.Start
在启动进程时查看那里-我不相信当UseShellExecute
是false
时它会这样工作。尝试只指定要启动的进程的绝对文件名:
process.StartInfo.FileName = @"C:'Projects'MyProgram.exe";
请注意,我还从您为FileName
属性分配的字符串末尾删除了空格-这完全有可能导致问题。
对于System32访问,如果您试图在x64上运行x86应用程序,那么您必须在文件名中使用" sysative "关键字而不是"System32"。
例如:代替:
C: ' Windows ' System32系统' whoiscl.exe
应该是:
C: ' Windows ' Sysnative ' whoiscl.exe
希望对大家有所帮助