2012-05-31 54 views

回答

0

我建議你閱讀PumpStreamHandlerInputStreamPumper。你基本上想要這些類。只需修改InputStreamPumper.run()循環。它應該激發你的事件而不是os.write()。要讓結果在運行過​​程中開始到達,請按如下方式調用它:

CommandLine cmdLine = new CommandLine(yourExecutable); 
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); 

Executor executor = new DefaultExecutor(); 
executor.setStreamHandler(new YourPumpStreamHandler()); 
executor.execute(cmdLine, resultHandler); 
// until waitFor returns, the process is running and events can be generated 
int exitValue = resultHandler.waitFor();