This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to close the command prompt open by Runtime.exec Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to close the command prompt open by Runtime.exec" Watch "How to close the command prompt open by Runtime.exec" New topic
Author

How to close the command prompt open by Runtime.exec

Rajesh kt
Greenhorn

Joined: Oct 29, 2009
Posts: 2
Hi All,

I have a cmd file as shown below.

set ANT_HOME=%ANT_HOME%

%ANT_HOME%/bin/ant build.xml

I have written a java code to

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd /c start/wait localbuild.cmd");
It works fine... opens a command prompt and runs the localbuild.cmd file .

Now i need to close this command prompt once it finished executing the cmd file.
How can i achive this...

Rajesh
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 377
creaate a command array and put exit as the last element.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Rajesh kt
Greenhorn

Joined: Oct 29, 2009
Posts: 2
thanks for the reply, but the command prompt get closed without executing the .cmd file
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Rajesh, please read your private messages.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 377
What you want to do?

How do you know whether the cnmd file executes or not?

Does it execute before you add exit int he array?
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 415
put "exit" in the last line of your localbuild.cmd. Without quotes, of course.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to close the command prompt open by Runtime.exec
 
Similar Threads
Clear Screen in java?
unable to run ant after unzipping binary distrbtn
What does System.exit(0); do?
Command Window Shutting Down....
WSDL2JAVA not generating all the classes with Axis 1.4