This discussion is archived
6 Replies Latest reply: Mar 5, 2007 2:54 AM by 807599 RSS

Two .exe files to run sequentially

807599 Newbie
Currently Being Moderated
Inside a class, I am running two .exe files. But even before the first .exe gets terminated, the second .exe file is getting executed.

Could someone please tell me how do I run these two .exe files sequentially.

At present no error is thrown, but the necessary number of files are not created from both the .exe files.
  • 1. Re: Two .exe files to run sequentially
    3004 Newbie
    Currently Being Moderated
    exec returns a reference to a Process. Process has a waitFor() method that will cause the curren thread to pause until the process finishes.
  • 2. Re: Two .exe files to run sequentially
    807599 Newbie
    Currently Being Moderated
    If I am right in understanding, is this what you meant for me to do. But still from the below code, before the execution of the first .exe, the second .exe is getting executed.

    Please tell me what updations to do in my code.
    public class Compile 
    {
         int flag=0;
         public Compile() 
         {
         }
    
         void compileFile(File newFile, String renameSub, File outputfile, String fontName, String IntallPath) throws IOException 
         {
              String FirstParam = "C:\\Temp\\Installation\\test.tex";   
              String FirstParam2 = "C:\\Temp\\Installation";
              String SecondParam = "C:\\Temp\\Installation";   
              try
              {
                   Process proc1 =Runtime.getRuntime().exec("cmd /c start /MIN tex " + FirstParam, (String[])null, new File(SecondParam));
                   InputStream stderr = proc1.getErrorStream();
                   InputStreamReader isr = new InputStreamReader(stderr);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   proc1.waitFor();
                   if(proc1.exitValue()==0)
                   {
                        System.out.println("tex is executed successfully");
                        flag=1;
                   }
              }
              catch (Throwable t)
              {
                   t.printStackTrace();
              }     
              if(flag==1)
              {
                   ... code for second .exe file ...
              }          
         }
    }
  • 3. Re: Two .exe files to run sequentially
    DrClap Expert
    Currently Being Moderated
    When you run this command:
    cmd /c start /MIN tex " + 
    you start a process that runs the "cmd" program. It starts a second process that runs the "tex" program and then ends immediately.

    So the process you started ("cmd") has ended. Your code has no way of knowing anything about the other process ("tex") and no way of waiting for it. If you want it to do that then you have to do something different.
  • 4. Re: Two .exe files to run sequentially
    807599 Newbie
    Currently Being Moderated
    If you want it to do that then you have to do something different.

    Can you please tell me how to go about with this.
  • 5. Re: Two .exe files to run sequentially
    807599 Newbie
    Currently Being Moderated
    If you want it to do that then you have to do
    something different.


    Can you please tell me how to go about with this.
    At the DOS prompt type

    help cmd
    help start

    and read and experiment.

    Google will find you more information.
  • 6. Re: Two .exe files to run sequentially
    807599 Newbie
    Currently Being Moderated
    Thanks for the info, my program is working in the desired manner.