[windows] Batch files : How to leave the console window open

I have two batch files, one of them executes another, i.e.

  1. "My Batch File" > 2. "Some Other Batch File"

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?

This question is related to windows batch-file

The answer is


I just press enter and type Pause and it works fine


put at the end it will reopen your console

start cmd 

I just written last line as Pause it worked fine with both .bat and .cmd. It will display message also as 'Press any key to continue'.


You can just put a pause command in the last line of your batch file:

@echo off
echo Hey, I'm just doing some work for you.
pause

Will give you something like this as output:

Hey, I'm just doing some work for you.

Press any key to continue ...

Note: Using the @echo prevents to output the command before the output is printed.


For leaving the console window open you only have to add to the last command line in the batch file:

' & pause'

In the last line of the batch file that you want to keep open put a

pause >nul


rem Just use "pause" at the end of the batch file.
...
......
.......
pause

At here:

cmd.exe /k "<SomePath>\<My Batch File>.bat" & pause

Take a look what are you doing:

  1. (cmd /K) Start a NEW cmd instance.
  2. (& pause) Pause the CURRENT cmd instance.

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"

Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to batch-file

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH CanĀ“t run .bat file under windows 10 Execute a batch file on a remote PC using a batch file on local PC Windows batch - concatenate multiple text files into one How do I create a shortcut via command-line in Windows? Getting Error:JRE_HOME variable is not defined correctly when trying to run startup.bat of Apache-Tomcat Curl not recognized as an internal or external command, operable program or batch file Best way to script remote SSH commands in Batch (Windows)