The Runtime.getRuntime().exec()
approach is quite troublesome, as you'll find out shortly.
Take a look at the Apache Commons Exec project. It abstracts you way of a lot of the common problems associated with using the Runtime.getRuntime().exec()
and ProcessBuilder
API.
It's as simple as:
String line = "myCommand.exe";
CommandLine commandLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
int exitValue = executor.execute(commandLine);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…