user32882
user32882

Reputation: 5877

Basic batch file language command

I would like to from my current command prompt open another command prompt and cd to a directory of my choice. I am currently doing the following:

start cmd /c "cd C:\Users"

I expect this to open a new command prompt and cd to that directory. I also expect it to show that cd command in the new command prompt. None of this is happening, only a brief second command window opening and closing out. What am I doing wrong here?

Upvotes: 1

Views: 221

Answers (2)

user6250760
user6250760

Reputation:

Instead of using pause, do cmd /k.

  • Flag c loses the cmd window.

  • Flag k eeps the cmd window opens

So, your code should be:

start "windowTitle" cmd /k "cd C:\Users"

Upvotes: 2

CodeCupboard
CodeCupboard

Reputation: 1585

On the line below include "pause" This will keep the window open promoting a key press. Keeping the cmd window open allows you to check it has done what you have asked. Cmd windows self terminate once all code has complete.

Upvotes: 1

Related Questions