How to write output of child process in Java -


i have written java code in eclipse , developing plug-in embed button on workbench. when button clicked, opens batch file (located in c:/program file/prism 4.0/bin)

the code opens .bat file ! next task write output of batch file on console. using eclipse ide version 3.

my code is

messageconsolestream out = myconsole.newmessagestream();         out.println("we on console ! \n shubham performed action");   try {        processbuilder pb=new processbuilder("c:\\program files\\prism-4.0\\bin\\prism.bat");         pb.directory(new file("c:\\program files\\prism-4.0\\bin"));         process p=pb.start();          int exitval=p.waitfor();                     out.println("exited error code "+exitval+" shown , action performed \n");              out.println("shubham process successful");             out.println("printing on console");          }         catch (exception e)         {             out.println(e.tostring());             e.printstacktrace();          }     }  

do this:

..... process p = pb.start();  bufferedreader input = new bufferedreader(new inputstreamreader(p.getinputstream()));  string in; while((in = input.readline()) != null) {     out.println(in); }  int exitval = p.waitfor(); ..... 

note if batch file writes standard error java program must consume otherwise p.waitfor() never return.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -