I have two batch files, one of them executes another, i.e.
I've created a shortcut of the first batch file and edited its properties to call its in following way.
cmd.exe /k "<SomePath>\<My Batch File>.bat" & pause
What i want to do I want the console window to be open after the execution of the batch file is over. Now it just closes, tried to play around the cmd flags, no result.
Platform : Windows7
UPDATE 1
Modified the structure, the simple example like this does not work as well, Only one batch file i.e. there is no the 2. "Some Other Batch File" The only batch file contains smth like this
start /B /LOW /WAIT make package cmd /K
UPDATE 2
The same shortcut which is invoked from Explorer does not close the console window. But the console window closes when the shortcut is invoked from the pinned item on taskbar
Any ideas how to keep the console window open?
Edit your bat file by right clicking on it and select “Edit” from the list. Your file will open in notepad. Now add “PAUSE” word at the end of your bat file. This will keep the Command Prompt window open until you do not press any key.
If you're creating a batch file and want the MS-DOS window to remain open, add PAUSE to the end of your batch file. This prompts the user to Press any key. Until the user presses any key, the window remains open instead of closing automatically.
If you want the command prompt cmd widnow to stay open after executing the last command in batch file –you should write cmd /k command at the end of your batch file. This command will prevent the command prompt window from closing and you'll get the prompt back for giving more commands in the cmd window.
If that is really all the batch file is doing, remove the cmd /K
and add PAUSE
.
start /B /LOW /WAIT make package PAUSE
Then, just point your shortcut to "My Batch File.bat"
...no need to run it with CMD /K
.
Ah, some new info...you're trying to do it from a pinned shortcut on the taskbar.
I found this, Adding Batch Files to Windows 7 Taskbar like the Vista/XP Quick Launch, with the relevant part below.
- First, pin a shortcut for
CMD.EXE
to the taskbar by hitting the start button, then type "cmd" in the search box, right-click the result and chose "Pin to Taskbar".- Right-click the shortcut on the taskbar.
- You will see a list that includes "Command Prompt" and "Unpin this program from the taskbar".
- Right-click the icon for
CMD.EXE
and selectProperties
.- In the box for Target, go to the end of
"%SystemRoot%\system32\cmd.exe"
and type" /C "
and the path and name of the batch file.
For your purposes, you can either:
Use /C
and put a PAUSE
at the end of your batch file.
OR
/K
and remove the PAUSE
from your batch file.At here:
cmd.exe /k "<SomePath>\<My Batch File>.bat" & pause
Take a look what are you doing:
How to resolve it? well,using the correct syntax, enclosing the argument for the new CMD instance:
cmd.exe /k ""<SomePath>\<My Batch File>.bat" & pause"
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