I'm running a batch file that has these two lines:
start C:\Users\Yiwei\Downloads\putty.exe -load "MathCS-labMachine1" "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
This batch file is used to run the Xming application and then the PuTTY app so I can SSH into my university's computer lab.
However, if I run this and Xming is not already open, once I exit from the PuTTY terminal the cmd window remains open. Only if I have already run Xming does the cmd window close when I close the PuTTY terminal. I've tried adding exit
to the last line of the batch file, but to no avail.
If the batch file was launched from a shortcut, "exit /b" should work fine.
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.
Alternatively referred to as Cmd+K, Command+K is a keyboard shortcut that varies depending on the program used. For example, in certain programs, Command+K is used to insert a hyperlink, and in some browsers, Command+K focuses on the search bar. Tip. On Windows computers, the most similar keyboard shortcut is Ctrl + K ...
Modify the batch file to START
both programs, instead of START
ing one and CALL
ing another
start C:\Users\Yiwei\Downloads\putty.exe -load "MathCS-labMachine1" start "" "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
If you run it like this, no CMD window will stay open after starting the program.
You normally end a batch file with a line that just says exit
. If you want to make sure the file has run and the DOS window closes after 2 seconds, you can add the lines:
timeout 2 >nul exit
But the exit
command will not work if your batch file opens another window, because while ever the second window is open the old DOS window will also be displayed.
SOLUTION: For example there's a great little free program called BgInfo which will display all the info about your computer. Assuming it's in a directory called C:\BgInfo
, to run it from a batch file with the /popup
switch and to close the DOS window while it still runs, use:
start "" "C:\BgInfo\BgInfo.exe" /popup exit
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