469,627 Members | 1,270 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

How to wait till the end of DOS program started using Runtime.exec(cmd)?

In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other batch file start.bat.

The piece of code which I am using is:
public static void ExecuteScripts(){
try {
\\Start the first batch program call.bat
Process p = Runtime.getRuntime().exec("cmd /c start .\\scripts\\call.bat");
p.waitFor();
System.out.println("Exit value "+p.exitValue());
\\Start the second batch program run.bat
Process p1 = Runtime.getRuntime().exec("cmd /c start .\\scripts\\run.bat");
}
catch (Exception e) {
e.printStackTrace();
}

For this piece of code it starts the first batch program(i.e, call.bat) in a command prompt and immediately it starts the second batch program (i.e, run.bat) in another command prompt. So it runs both the batch programs simultanesously. But what I wanted is that my program should wait till the first batch is executed and then start the second batch.

Please tell me how to wait between these two runtime commands in JAVA

With regards,
C.Chenthil.
-------------------
Jan 22 '07 #1
5 24729
horace1
1,510 Expert 1GB
I think it is because you are using the start command - remove it and you should be OK
Jan 22 '07 #2
horace1
1,510 Expert 1GB
alternativly if you need Command Prompt Windows try the /wait parameter to start, e.g.
Expand|Select|Wrap|Line Numbers
  1.       Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");
  2.  
the final command in the batch files should be exit
Jan 22 '07 #3
alternativly if you need Command Prompt Windows try the /wait parameter to start, e.g.
Expand|Select|Wrap|Line Numbers
  1.       Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");
  2.  
the final command in the batch files should be exit

Thanks a lot yar... This [Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");] worked fine.

Thanks a lot for your timely help
Jan 23 '07 #4
horace1
1,510 Expert 1GB
Thanks a lot yar... This [Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");] worked fine.

Thanks a lot for your timely help
good to hear it worked - I find the following site useful for Windows command line infotrmation
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true
Jan 23 '07 #5
Thank you very much chenthil
Your reply of cmd /c /start/wait worked perfectly alright.
Thanks a ton,
Jul 24 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Ayesha Ahsan | last post: by
2 posts views Thread by uwnewsgroup | last post: by
3 posts views Thread by Schüle Daniel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.