我正在編寫一個運行命令行的代碼,使用默認的apache執行程序。 我找到了獲取退出代碼的方式,但我找不到獲取進程ID的方法。用java獲取進程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做什麼?
看看[這個](http://stackoverflow.com/questions/5174426/graceful-kill-of-apache-commons-exec-process)。 – 2013-03-24 16:50:05
Im正在使用Windows ... – Rivi 2013-03-27 07:44:53