【发布时间】:2020-10-07 08:27:29
【问题描述】:
我有一个 Excel 表,其中包含要执行的 jar 文件列表。为了开始测试,我将运行一个代码从上述 excel 表中读取并执行 excel 表中的 jar 文件。运行这些 jar 文件的代码如下:
final Process p = Runtime.getRuntime().exec("cmd /c start cmd /k java -jar " + start.jar_filepath + " " + start.tc_name + " " + start.test_data + " " + start.test_result + " " + start.test_cycle);
这实际上会同时运行所有的 jar 文件。
我实际上希望一次执行一个 jar,并且在当前 jar 完成执行后执行下一个 jar。
我添加了以下内容。
p.waitFor();
但是,它的行为仍然相同,即同时执行。
我是否错误地使用了 waitFor() ?感谢您的建议。
更新: 下面是遍历excel表格的代码
public static void main(final String[] args) throws IOException, Throwable {
final DataFormatter df = new DataFormatter();
final FileInputStream StartInput = new FileInputStream("c:\\TA\\TestConfig_MA.xlsx");
final XSSFWorkbook StartInputWB = new XSSFWorkbook(StartInput);
final XSSFSheet sheet = StartInputWB.getSheet("Config");
System.out.println("Amount of Row in test config : "+ sheet.getLastRowNum());
start.count = 1;
//while (start.count <= sheet.getLastRowNum()) {
for(start.count = 1; start.count <= sheet.getLastRowNum(); start.count++){
System.out.println("Total test case = " + sheet.getLastRowNum());
System.out.println(start.count);
final XSSFRow row = sheet.getRow(start.count);
start.testability = row.getCell(0).toString();
start.jar_filepath = row.getCell(1).toString();
start.tc_name = row.getCell(2).toString();
start.test_data = row.getCell(3).toString();
start.test_result = row.getCell(4).toString();
start.test_cycle = df.formatCellValue(row.getCell(5));
System.out.println("test cycle from start.jar = " + start.test_cycle);
System.out.println("Test Case Name : " + start.tc_name);
if (start.testability.equals("Y") || start.testability.equals("y)")) {
System.out.println("Test Case Name : " + start.tc_name);
System.out.println("Round : " + start.count);
final Process p = Runtime.getRuntime().exec("cmd /c start cmd /k java -jar " + start.jar_filepath + " " + start.tc_name + " " + start.test_data + " " + start.test_result + " " + start.test_cycle);
p.waitFor();
System.out.println("wait for = " +p.waitFor());
else {
System.out.println("Its a no");
}
// ++start.count;
}//for
System.out.println("test is done");
}
}
【问题讨论】:
-
您能否提供一个minimal reproducible example,您可以在其中展示您如何循环遍历 excel 行、您如何等待以及如何处理异常。目前我们无法告诉您您是否做错了什么,因为我们没有足够的信息
-
@Lino 很高兴。让我补充一下主要问题