473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 25201
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

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

Similar topics

5
by: JW | last post by:
Hi, I don't seem to get any results from the following use of Runtime.getRuntime().exec(cmd) using Java 1.4 on Redhat linux. Suppose that in the same directory as my java file below, I have...
5
by: Ayesha Ahsan | last post by:
Hi, I use Runtime.getRuntime().exec(command) to make my system call. For Windows based Dos, i add "cmd /c" before I type in my system call. So for example make the system call "dir": String...
2
by: uwnewsgroup | last post by:
When I was using Runtime.exec(String cmd) to run a unix utility (join), and try to get its standard output by using Process.getOutputStream(), it blocks forever. I tried it using Java 1.4 and...
2
by: James Goldwater | last post by:
I have a situation where I actually _do_ want the command window to show after a runtime.exec() call. (Although we pipe stout/stdin to our own logging mech, the program needs to be able to trap...
3
by: Schüle Daniel | last post by:
Hello all, >>> p = "z%i = complex(1-1e-%i, 1-1e-%i)" >>> lst = >>> for item in lst: .... exec item .... >>> >>> p = "z%i = complex(1-1e-%i, 1-1e-%i)" >>> lst =
8
by: angelotti | last post by:
Hi everyone , i am banging my head over the following problem for a couple of weeks now: i am starting a MyProg.exe(a simple C app) from a java class with .exec() as a system process(not in it's own...
2
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the...
1
by: wavespirit75 | last post by:
Hi, I wrote a program which will use ffmpeg to convert media files. Media files can be converted with this string array being passed in to Runtime.getRunTime().exec: String cmd = {ffmpeg path,...
0
by: Manuel Elias | last post by:
I have three PC : PC1 : WinXP Pro PC2 : Win2003 Server x64 PC3 : Win 7 x64 PC1 & PC2 can connect to PC3 via a VPN (PPTP) using windows menu to launch a configured VPN connection MyPVN. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.