I have a Java application in which user can give any executable file (.exe) and the application will run it on the system. Like cmd.exe, notepad.exe or on unix a.out etc.

Now the code I have written after going through numerous examples just doesnt seem to work for the user created files notepad.exe works fine but the files written using TC++ and all don't work. Can anyone point out what can be the cause of the error here?

```
 import java.io.*;

 class NewThread implements Runnable{
    Thread t;

    NewThread(){
        t = new Thread(this, "Demo Thread");
        System.out.println("child thread:" + t);
        t.start();      
    }

    public void run(){
        try
        {
        String line;    
        Process p = Runtime.getRuntime().exec("C:\\TC\\BIN\\AA.EXE");
        InputStream in = p.getInputStream();
        OutputStream out = p.getOutputStream();
        InputStream err = p.getErrorStream();
        BufferedReader br= new BufferedReader(new InputStreamReader(in));
        System.out.println("Chid running");
        while((line=br.readLine())!=null){
            System.out.println(line);
        }
        //p.destroy();

                }
        catch (Exception e)
        {
            System.out.println("ERROR");

        }
        System.out.println("Child thread exiting");

}
}
    class ThreadDemo {
        public static void main (String args[]){
            new NewThread();
            try {
                for(int i=05;i>0;i--){
                    System.out.println("Main Thread:" + i);
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e){
                System.out.println("Main thread Interrupted");
            }
            System.out.println("Main thread exiting");
        }
    }

```

....OK...doesn't work means When I run it using Eclipse-> Child thread exits[all the system.out messages are printed on console but not the ones to be printed by .exe AA.exe doesn't run at all. Some other points:

> 
> 1. It runs normally, No exceptions are thrown only problem is Output of
>  AA.exe is not visible anywhere.
> 2. It prints an exit code 7 for the process p...any clue????
> 3. notepad.exe or MSWord.exe and even TC.exe are running perfectly normal
>  when invoked through this code.
> 
> 
> 

here's the code for AA.exe:

```
  #include <stdlib.h>
#include <stdio.h>
#include <values.h>
#include <time.h>

int main(void)
{
   int i,j;

      for(j=0;j<150;j++)
      {
     // randomize();
      for(i=0;i<200;i++)
     printf("%d\n", rand() % MAXINT);
      }
   return 0;
}

```