我试图运行一个调用Java类的bat文件,我想通过提供输入并使用Java从命令窗口中读取输出来继续与命令窗口进行交互。但是我只能阅读命令提示符的第一行,而不知道如何进一步与之交互。在执行批处理文件时,它会提示我们输入文件名,一旦输入文件名,它会询问其他详细信息
使用进程生成器和plexus util进行了尝试,我无法在执行第一个命令后弄清楚如何运行第二个命令。
尝试使用以下代码
public class plexus {
public plexus() {
String batfile = "regression-test-runner-steadfast.bat";
String directory = "C:\\Dev\\temp\\IOS-automation-test\\Steadfast-UAT-Regression-Test-Runner-Client-dist";
try {
runProcess(batfile, directory);
} catch (CommandLineException e) {
e.printStackTrace();
}
}
public void runProcess(String batfile, String directory) throws CommandLineException {
Commandline commandLine = new Commandline();
File executable = new File(directory + "/" +batfile);
commandLine.setWorkingDirectory(directory);
commandLine.setExecutable(executable.getAbsolutePath());
commandLine.createArg().setValue("C:\\Users\\U399526\\Desktop\\SVU_XML\\Scenario 1");
WriterStreamConsumer systemOut = new WriterStreamConsumer(
new OutputStreamWriter(System.out));
WriterStreamConsumer systemErr = new WriterStreamConsumer(
new OutputStreamWriter(System.out));
int returnCode = CommandLineUtils.executeCommandLine(commandLine, systemOut, systemErr);
if (returnCode != 0) {
System.out.println("Something Bad Happened!");
} else {
System.out.println("Taaa!! ddaaaaa!!");
};
}
public static void main(String[] args) {
new plexus();
}
}