我正在编写一个启动测试器 (.cmd) 的应用程序,因此我正在传递已输入到列表框中的测试。如果输入了一个测试,此方法工作得很好,但如果有 2 个或更多,它会给我错误:
“System.dll 中发生‘System.ComponentModel.Win32Exception’类型的未处理异常附加信息:系统找不到指定的文件”
和两者在调试器中看起来都是正确的StartInfo.Filename
。currentTestFromListbox[i]
有人知道我哪里出错了吗?
我很抱歉我的代码令人困惑——我只是一个初学者。
public void executeCommandFiles()
{
int i = 0;
int ii = 0;
int numberOfTests = listboxTestsToRun.Items.Count;
executeNextTest:
var CurrentTestFromListbox = listboxTestsToRun.Items.Cast<String>().ToArray();
string filenameMinusCMD = "error reassigning path value";
int fileExtPos = CurrentTestFromListbox[i].LastIndexOf(".");
if (fileExtPos >= 0)
{
filenameMinusCMD = CurrentTestFromListbox[i].Substring(0, fileExtPos);
}
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = @"pushd Y:\Tests\" + filenameMinusCMD + @"\" + CurrentTestFromListbox[i];
startInfo.WorkingDirectory = @"pushd Y:\Tests\" + filenameMinusCMD + @"\";
startInfo.FileName = CurrentTestFromListbox[i];
Process.Start(startInfo);
//Wait for program to load before selecting main tab
System.Threading.Thread.Sleep(10000);
//Select MainMenu tab by sending a left arrow keypress
SendKeys.Send("{LEFT}");
i++;
if (i < numberOfTests)
{
checkIfTestIsCurrentlyRunning:
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains("nameOfProgramIAmTesting"))
{
System.Threading.Thread.Sleep(2000);
//if (ii > 150)
if (ii > 6) //test purposes only
{
MessageBox.Show("The current test (" + filenameMinusCMD + ") timed out at 5 minutes. The next test has been started.", "Test timed out",
MessageBoxButtons.OK,
MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1);
}
ii++;
goto checkIfTestIsCurrentlyRunning;
}
goto executeNextTest;
}
}
}
}
谢谢!-乔尔