在设置进程时,似乎我没有以正确的方式使用变量"WorkingDirectory"。我会收到以下错误信息(包含一个catch):
ApplicationName='Test.exe',CommandLine='/d=1',CurrentDirectory='C:\Users\mb\Desktop\Integration\Tests\dailyTest\dailyTest\bin\Debug\Stress',Native error=The system cannot find the file specified.
然而,在文件夹"Stress"中确实存在一个"Test.exe",所以我真的不理解这意味着什么。
为什么会出现失败,如何解决?
代码如下(请注意,我已经将变量替换为直接字符串内容,以便更好地理解)。
ApplicationName='Test.exe',CommandLine='/d=1',CurrentDirectory='C:\Users\mb\Desktop\Integration\Tests\dailyTest\dailyTest\bin\Debug\Stress',Native error=The system cannot find the file specified.
然而,在文件夹"Stress"中确实存在一个"Test.exe",所以我真的不理解这意味着什么。
为什么会出现失败,如何解决?
代码如下(请注意,我已经将变量替换为直接字符串内容,以便更好地理解)。
Process proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\" + "Stress");
proc.StartInfo.FileName = "Test.exe";
proc.StartInfo.Arguments = "/d=1";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start ();
proc.WaitForExit();
return proc.ExitCode;
我知道WorkingDirectory受UseShellExecute的影响,但我尊重它。
Directory.GetCurrentDirectory() + "\\" + "Stress"
,这就是为什么 Path.combine 存在的原因。 - BCdotWEB