I have a batch file with for example
cd c:\test
But there is more then this in the batch, it's just an example.
So, if I call it from explorer, I see a cmd window for short time and then it will be closed. How can I avoid this?
I tried to call PAUSE at the end, but for me it's cheating :)
UPD:
just imagine, I'm lazy and need to call different batches from different directories very often. That's why I wanted to have my batches in just one diretory calling another batches, but I also want to see results after execution
Type the "cmd /k" parameter before every command to keep the window from closing.
Pressing "y" would use the goto command and go back to start and rerun the batch file. Pressing any other key would exit the batch file.
Batch file processing ends when execution reaches the end of the batch file. The trick therefore is to use the goto command to jump to a label right before the end of the file, so that execution “falls off the end”.
I presume you are double clicking on the batch file from within Windows Explorer (or else right clicking and selecting open). If so, then you are getting the expected behavior. When you double click on any executable, the window should close once the executable completes.
Putting a PAUSE before the end is the appropriate technique to allow you to see the results before the Window closes. It is not cheating.
If you want the command window to remain open after the batch file terminates, then you can use an appropriately configured shortcut.
Assume the batch file is C:\MyPath\TEST.BAT. You create a shortcut for it, right mouse click on the shortcut, and edit properties. Modify the Target: as follows:
cmd /k "C\MyPath\TEST.BAT"
If you double click on the shortcut, TEST.BAT will run and the command window will remain open after it terminates. But now the command window will remain open indefinitely until you explicitly close it.
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