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
}

Advertisements

1 Comment

  1. Ecko said,

    June 14, 2010 at 11:48 am

    Thanks for sharing,,,


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: