0

For some reason I cannot open the cmd. I created a simple bat file that does dir but it immediately closes the cmd as well. Is there a way I can keep the cmd open with some command?

  • 1
    You mean using a batch (.bat) file script? – James Mertz May 21 '14 at 17:38
  • 1
    Wouldn't it be a lot more practical to just fix the problem of not being able to open a command prompt? – Moses May 21 '14 at 18:01
5

Adding pause at the end of the batch script should keep it open until you press any key to continue.

  • this works expect that it doesn't accept new input after completing the pause – user325563 May 21 '14 at 17:43
  • because it closes again. – user325563 May 21 '14 at 17:45
  • Are you running the script from the command line or double clicking it? It would help if you provided the code for the script. – Pak May 21 '14 at 17:45
  • 4
    The reason I asked for the code was because I wanted to see if you had an exit at the end. If you're just trying to start a command prompt and have it print the directory listing first, then in your script you could do something like start cmd /K dir. Run cmd /? for details on the /K option. – Pak May 21 '14 at 17:53
  • 1
    Unfortunately I don't have a Windows 10 system that I can try this on, but I would be quite surprised if they removed the pause command. Are you certain that the rest of the script is working correctly? If one of the previous commands in the script is also a batch script and it's not being called by using the call statement, then the the script will terminate before getting to the pause. – Pak May 12 '17 at 17:12
1

try this:

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

protected by Community Apr 25 '18 at 12:20

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.