This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
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: 385
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: 19656
    
  18

Rajesh, please read your private messages.


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

Joined: Sep 19, 2008
Posts: 385
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: 417
put "exit" in the last line of your localbuild.cmd. Without quotes, of course.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to close the command prompt open by Runtime.exec
 
Similar Threads
What does System.exit(0); do?
Clear Screen in java?
WSDL2JAVA not generating all the classes with Axis 1.4
unable to run ant after unzipping binary distrbtn
Command Window Shutting Down....