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
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With