Closing cmd window after executing bat file

Just a small post you may find useful if you are as annoyed as I was of a command window left open after execution of a bat file.

I had to call an exe with some options. So I wrote a bat for it. But after executing the bat file, it always kept a command window open until I explicitly close it or the executed program finishes. Actually the command window remains open till the control is returned from the exe to bat again. Point to be noted is EXIT doesn't help in this case as it's call is also deferred until control is returned back.

eg.

start-netbeans.bat
netbeans --jdkhome d:\dev\jdk

putty-to-server.bat
d:\programs\putty -pw password username@ip-addrs

Use start before the command so your bat calls the exe and continues its execution i.e. doesn't wait for the exe to complete the execution

start netbeans --jdkhome d:\dev\jdk

start d:\programs\putty -pw password username@ip-addrs

You can use pause command for "Press any key to continue . . ."

8 comments:

ryant@devsanctum.com said...

You do this without using a batch file. You can create a shortcut and put your command line options into it.

kunal said...

@ryan nice suggestion. I really never thought about this. Although i may still need a .bat for multi-line scripts but this will solve the problem for the ones and likes that i put in example.

anantshri said...

oh, it didn't occured to me, was doing simmilar stuff for shell script @GNU/Linux but seems to be getting to old for batch scripting now. <- nearly 2 yrs since my last batch file.

But now pause and start both in my list.....

Giri said...

It was really helpful for me. i was looking for a solution exactly like this. thanks a lot. :)

Giri said...

It was really helpful for me. i was looking for a solution exactly like this. thanks a lot. :)

Karthik said...

Saved my day :) Thanks!!

Anonymous said...

Thanks for sharing this tip !

Anonymous said...

Thanks for sharing, saved me a lot of aggravation!