Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close the command line window after running a batch file?

I've got a batch file. After it finished running, i.e. all command lines have been executed, the cmd.exe window stays open. However, I'd like to have it closed right after the batch file finishes its job.

So far I've tried using the exit command within the batch file to close the cmd window (I also have a shortcut on the desktop) but it doesn't seem to work:

tncserver.exe C:\Work -p4 -b57600 -r -cFE -tTNC426B exit 
like image 936
Blitzcrank Avatar asked Jan 31 '13 12:01

Blitzcrank


People also ask

How do I close a command prompt window?

To close or exit the Windows command line window, also referred to as command or cmd mode or DOS mode, type exit and press Enter . The exit command can also be placed in a batch file. Alternatively, if the window is not fullscreen, you can click the X close button in the top-right corner of the window.

How do you close cmd window after execute in C#?

Arguments = "/k " + Command + " & exit"; But if you read the "cmd /?", you'll see that the purpose of "/k" argument is to keep the window. So if it's not what you want, just use the "/c" argument instead.


2 Answers

It should close automatically, if it doesn't it means that it is stuck on the first command.

In your example it should close either automatically (without the exit) or explicitly with the exit. I think the issue is with the first command you are running not returning properly.

As a work around you can try using

start "" tncserver.exe C:\Work -p4 -b57600 -r -cFE -tTNC426B 
like image 120
Bali C Avatar answered Sep 29 '22 17:09

Bali C


Your code is absolutely fine. It just needs "exit 0" for a cleaner exit.

 tncserver.exe C:\Work -p4 -b57600 -r -cFE -tTNC426B  exit 0 
like image 22
Gaurav Kolarkar_InfoCepts Avatar answered Sep 29 '22 15:09

Gaurav Kolarkar_InfoCepts