19

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.

Tuan
  • 2,883
  • 4
  • 32
  • 54
iDon'tKnow
  • 201
  • 1
  • 2
  • 4
  • 2
    possible duplicate of [How to prevent auto-closing of console after the execution of batch file.](http://stackoverflow.com/questions/988403/how-to-prevent-auto-closing-of-console-after-the-execution-of-batch-file) – kapa Dec 28 '14 at 11:19

3 Answers3

64

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

Endoro
  • 34,892
  • 8
  • 45
  • 61
5

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.

Radreaps
  • 51
  • 1
  • 1
3

end your bat file with @pause on its own line

ThinkingStiff
  • 62,391
  • 29
  • 139
  • 237
bizzehdee
  • 17,878
  • 9
  • 41
  • 70
  • 2
    @pause seems to do the same as just pause. It wont let me write, it closes no matter what i press. – iDon'tKnow Feb 21 '13 at 21:34
  • 1
    ahh, your after the script changing directory for you and then you doing more stuff manually yourself? "cmd C:\Users\Hello\Documents\Stuff". the bat file runs as if it is its own app, you need to tell it to launch a new instance of cmd – bizzehdee Feb 21 '13 at 21:37
  • Once i get it to launch a new cmd, can i then get it to close the old? So i only have one open. Or maybe just run the old hidden? I know you can hide text with "@echo off", perhaps also for the whole cmd? – iDon'tKnow Feb 21 '13 at 21:49
  • thanks @Endoro. Googling for 10 minutes and "very last line of the script" is the key here. – paIncrease Jun 14 '14 at 19:23