我正在编写一个使用 apache 的默认执行程序运行命令行的代码。我找到了获取退出代码的方法,但我找不到获取进程 ID 的方法。
我的代码是:
protected void runCommandLine(OutputStream stdOutStream, OutputStream stdErrStream, CommandLine commandLine) throws InnerException{
DefaultExecutor executor = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(stdOutStream,
stdErrStream);
executor.setStreamHandler(streamHandler);
Map<String, String> environment = createEnvironmentMap();
try {
returnValue = executor.execute(commandLine, environment);
} catch (ExecuteException e) {
// and so on...
}
returnValue = e.getExitValue();
throw new InnerException("Execution problem: "+e.getMessage(),e);
} catch (IOException ioe) {
throw new InnerException("IO exception while running command line:"
+ ioe.getMessage(),ioe);
}
}
我应该怎么做才能获得 ProcessID?