How to get the output of a console application from Java

Of course; I was trying to get a thread dump using jstack here. You would need to change the command that Runtime.exec() executes to your liking.

Process threadDump=Runtime.getRuntime().exec("jstack -l "+pid);
BufferedReader br=new BufferedReader(new InputStreamReader(threadDump.getInputStream()));
while(true)
{
String line=br.readLine();
if(line==null)
      break;
else {
      //Do whatever you want
}

1 Comment

  1. Ecko said,

    June 14, 2010 at 11:48 am

    Thanks for sharing,,,


Leave a comment