ProcessBuilder 和从类文件运行的新进程

问题描述 投票:0回答:0

尝试使用 processBuider 参数运行 cmd

    Runnable myRunnable = new RunTest(line);
    Thread treadForSingleTest = new Thread(myRunnable);
    treadForSingleTest.start();
    try {
        Thread.sleep(msTimeout);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

对于每个线程

private void startNewTestLineFlow(String line) {
    //get current date and time
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    Date date = new Date();
    String dateString = dateFormat.format(date);

    //create logfile
    String writeFileName = dateString + "_" + line + fileExtension;
    File file = new File(outputPath + writeFileName);

    //configuring QA Config
    try {
        file.createNewFile();
        File currDir = new File(".");
        String path = currDir.getAbsolutePath();
        path = path.substring(0, path.length() - 1);
        String command = ".;" + path + "repository\\org\\selenium\\4.4.0\\*";
        String name = className.get(line);
        List<String> commands = Arrays.asList("cmd.exe", "/C", "start", "java", "-cp", command, name, server, file.toString());
        ProcessBuilder builder2 = new ProcessBuilder(commands);
        builder2.directory(new File(path + "\\modules\\configuration\\build\\idea\\testClasses"));
        builder2.start();
    } catch (Exception e) {
        writeToLogFile(file, e.getMessage());
    }

但是当我尝试从类文件运行时

start cmd.exe @cmd /k "java -cp .;%projectDir%\repository\org\selenium\4.4.0\* selenium.logs_util.FileLogger"

它在同一 cmd 窗口中为行打开新的 cmd,停止之前的测试

感谢帮助

尝试超时,重建类文件,无线程运行

java cmd processbuilder
© www.soinside.com 2019 - 2024. All rights reserved.