Forum Discussion

avidCoder's avatar
avidCoder
Super Contributor
7 years ago

How to wait for the first command prompt to complete commands and then invoke another command prompt

I have written a program in java to call .bat file from local and run it in command prompt. I need to run different .bat file one by one. i don't know how much time it will be taken by the 1st command prompt to complete the execution. What I want is, once the 1st command prompt execution is completed then only invoke the 2nd command prompt and so.. on. i have used sleep() method but this will not be dynamic.. Here is the code :-

 

Process proc=Runtime.getRuntime().exec("cmd /c start c:\\Demo\\user.bat");
proc.waitForOrKill(5000)

 

Process proc=Runtime.getRuntime().exec("cmd /c start c:\\Demo\\user1.bat");
proc.waitForOrKill(5000)

 

Process proc=Runtime.getRuntime().exec("cmd /c start c:\\Demo\\user2.bat");
proc.waitForOrKill(5000)

 

 

 

 

 

No RepliesBe the first to reply