473,520 Members | 3,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 25213
horace1
1,510 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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
chenthil
2 New Member
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 Recognized Expert Top Contributor
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
aabhijit
1 New Member
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
40441
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 files junk1, junk2, junk3, and i want to have the java program delete all of these files.
5
14389
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 command="cmd /c dir"; Runtime.getRuntime().exec(command); What is the equivalenr of cmd /c in Unix .
2
11064
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 the results are the same on SunOS 5.8, Redhat8.0, cygwin. I read relevant articles and find the reason is that the output of the process exceeds...
2
2945
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 Ctrl-C keystrokes). Our application is launched by javaw. In Java 1.3.1, this behaviour was present (and much resented it looks like) but in 1.4+...
3
1791
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
9577
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 console) and i would like to communikcate with its I/O before it is finished. I don't have this issue if for instance i am starting another java app....
2
6848
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 program. That works for 95 %, but the other 5 % it doesn't. It seems to me that the started process just hangs, and therefor my program hangs, too...
1
2547
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, "-i", input file, output file}; However with the above method I couldn't set any options like "-s 176x144" for the output file's resolution, meaning if I...
0
1129
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. PC1 & PC2 can connect to PC3 using console command : "rasdial.exe MyVPN login password"
0
7324
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7627
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7203
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5765
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3295
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3295
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
855
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
529
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.