public static void consumeProcessConsole ( Process process , Listener < String > outputListener , Listener < String > errorListener ) { Application app = LCCore . getApplication ( ) ; ThreadFactory factory = app . getThreadFactory ( ) ; Thread t ; ConsoleConsumer cc ; cc = new ConsoleConsumer ( process . getInputStream ( ) , outputListener ) ; t = factory . newThread ( cc ) ; t . setName ( "Process output console consumer" ) ; cc . app = app ; cc . t = t ; t . start ( ) ; app . toInterruptOnShutdown ( t ) ; cc = new ConsoleConsumer ( process . getErrorStream ( ) , errorListener ) ; t = factory . newThread ( cc ) ; t . setName ( "Process error console consumer" ) ; cc . app = app ; cc . t = t ; t . start ( ) ; app . toInterruptOnShutdown ( t ) ; }
Launch 2 threads to consume both output and error streams and call the listeners for each line read .