Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to close the command prompt open by Runtime.exec

 
Rajesh kt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
creaate a command array and put exit as the last element.
 
Rajesh kt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply, but the command prompt get closed without executing the .cmd file
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh, please read your private messages.
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put "exit" in the last line of your localbuild.cmd. Without quotes, of course.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic