Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep cmd running after opening a .bat file script

Basically I have written a "script" in notepad and saved it as a .bat file. All it does is to change directory. Written like this:

cd C:\Users\Hello\Documents\Stuff 

It does change the directory, but i want to write more after that, within the cmd. Ex. choose a program to run. It seems simple, but i can't figure it out. I read about pause, but it just waits for a key and then closes down.

like image 216
iDon'tKnow Avatar asked Feb 21 '13 21:02

iDon'tKnow


People also ask

How do I keep the Command Prompt window open after a batch file?

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.

How do I keep cmd open after execution?

Type the "cmd /k" parameter before every command to keep the window from closing.

How do I stop a batch script from closing?

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.

How do I stop Command Prompt from closing automatically?

To prevent the Command Prompt from closing automatically:Press Windows key + R to open the Run window. Adding / K after the command keeps the window open. You can, then, close the window manually when you no longer need it to be open.


2 Answers

Put cmd /k on the very last line of the script.

like image 181
Endoro Avatar answered Nov 09 '22 02:11

Endoro


Try the following:

@echo off
Cmd /k

cmd /k starts a new cmd instance, /k stops terminating the console window after the commands are finished.

like image 32
Radreaps Avatar answered Nov 09 '22 03:11

Radreaps