0
我有以下代码来运行基于cmd行的求解器。在C#中启动进程并传递一个xml文件
//Create process
var pProcess = new System.Diagnostics.Process();
//strCommand is path and file name of command to run
const string strCommand = // where .bat file is
pProcess.StartInfo.FileName = strCommand;
//strCommandParameters are parameters to pass to program
string strCommandParameters = " -xml '" + xmlFile +"'";
pProcess.StartInfo.Arguments = strCommandParameters;
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
//Start the process
pProcess.Start();
//Get program output
this.StrOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
当我运行它是例外的是,它无法找到我传递给它的文件,当我注释掉UseShellExecute和RedirectStandardOutput它运行正常,但信息不进我的这一点。 StrOutput,当我注释掉useShellExecute时,重定向指出useShellExecute未设置为false。我如何正确地提供我的.xml文件,并将cmd行中的信息成功提交到我的strOutput中?
我喂完整路径C:\ ....为.bat文件和.xml文件。我是否错过了某些东西,或者我应该能够避免设置工作目录吗? – PlTaylor
您是否曾尝试在调用子进程之前测试此代码中的文件路径? - System.IO.File.Exists(文件) – IanNorton
测试真实,没有任何修改我的nunit测试。 – PlTaylor