【发布时间】:2015-08-09 14:25:24
【问题描述】:
在设置流程时,我似乎没有以正确的方式使用该变量 WorkingDirectory。我得到了错误(有问题)
ApplicationName='Test.exe', CommandLine='/d=1', CurrentDirectory='C:\Users\mb\Desktop\Integration\Tests\dailyTest\dailyTest\bin\Debug\Stress', Native error=系统找不到指定的文件。
但是在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 影响,但我尊重这一点。
【问题讨论】:
-
向我们展示您用于创建流程的代码。
-
看原帖!!
-
尝试使用工作目录而不是只使用文件名的整个路径
-
我会使用整个路径作为文件名,还包括工作目录。对于这两个,我会使用 Path.Combine 来构建路径。
-
不要做
Directory.GetCurrentDirectory() + "\\" + "Stress",这就是Path.combine存在的原因。