Claudiu
Claudiu

Reputation: 229281

Make windows batch file not close upon program exit

When the program is over, I want it to say "Press any key to continue..." so I can scroll thru the output.

Upvotes: 24

Views: 56527

Answers (6)

Nitin
Nitin

Reputation: 11

If you want the console to remain open, you can add the following at the end of batch file -

call cmd

This will open console with in the same one with all your environment variables set in your batch file and you can work in it.

Upvotes: 1

Mohammad Anini
Mohammad Anini

Reputation: 5220

In Windows/DOS batch files:

pause

This prints a nice Press any key to continue . . . message

Or, if you don't want to show anything message, do this instead:

pause >nul

Upvotes: 4

Rodrigo
Rodrigo

Reputation: 577

Create a shortcut to your batch file.

Right click on the file and select "Properties".

In the tab "Shortcut" is the target, something like this:

C:\folder\file.bat

Change it by this one:

C:\Windows\System32\cmd.exe /K "C:\folder\file.bat"

where "C:\Windows\System32" is the folder where cmd.exe is located, which may be another according to your Windows installation.

Then you can run the shortcut.

Upvotes: 2

Zombie Stephen
Zombie Stephen

Reputation: 1

you need to type in pause, which when you make it to the end, it should say

Press any key to continue . . .

but only if you put it at the end, because if you don't, it will pause it at the place you put it. Don't try '/k' because it doesn't work

Upvotes: 0

Anand Shah
Anand Shah

Reputation: 14913

A part of me says that "pause" in the batch file should also do the trick. But also give the /K switch a try as well.

HTH

Upvotes: 1

TheJacobTaylor
TheJacobTaylor

Reputation: 4143

I believe you are looking for the command "pause". It should ask you to press any key.

You can even appear to change the prompt. Instead of just using the pause statement, you can:

echo "Your message here"
pause > nul

This gets rid of the original pause message and inserts yours.

Jacob

Upvotes: 45

Related Questions