Wednesday, March 18, 2009

Tracing output from Exe in JAVA

Hello Everyone,

Suppose you are creating a exe files from you jar files.
So while running how to trace the output of application.

Here i am putting very small code to do so.
The idea behind this is make a object of process and execute a exe from runtime object.

get a inputstream reader from process.
Then trace the output.

Just see below.

/*
* Program for tracing a output from a executable
* Copyright 2009 @ yuvadeveloper
* Code By:- Prashant Chandrakar
*/
import java.io.*;
import javax.swing.JOptionPane;
import java.net.BindException;

class Loader
{
          public static void main(String as[])
          {
                   try
                   {
                             //pass the name of your exe in place of my.exe
                             Process p = Runtime.getRuntime().exec("DicomViewer.exe");

                             //getting inputstream reader from process
                             BufferedReader reader = new BufferedReader(new                   
                                        InputStreamReader(p.getInputStream()));
                             String line = reader.readLine();
                             while (line != null)
                             {
                                      line = reader.readLine();
                                      System.out.println(line);
                             }
                             reader.close();
                   }
                   catch (Exception e)
                   {
                   }
          }
}

No comments:

Post a Comment