By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,179 Members | 2,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,179 IT Pros & Developers. It's quick & easy.

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

P: 2
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
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 1,510
I think it is because you are using the start command - remove it and you should be OK
Jan 22 '07 #2

Expert 100+
P: 1,510
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

P: 2
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

Expert 100+
P: 1,510
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

P: 1
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.