2

I have the following directory structure:

I've created the StartAll.bat script in order to open a CMD window in each folder:

start cmd.exe /k cd Folder1 & set prompt=Folder1: start cmd.exe /k cd Folder2 & set prompt=Folder2: start cmd.exe /k cd Folder3 & set prompt=Folder3: start cmd.exe /k cd Folder4 & set prompt=Folder4: 

However, I'm experiencing a very weird behavior when running it:

  • The 1st window shows the entire path to Folder1
  • The 2nd window shows Folder1:
  • The 3rd window shows Folder2:
  • The 4th window shows Folder3:

enter image description here

As you can see, a proper window for the last folder is missing.

I'm observing the exact same behavior regardless of the number of folders.


Any idea what is going on here?

I would also appreciate alternative suggestions for achieving this purpose.

For all it matters, I am running this on Windows 10.

Thank you for your help.

0

1 Answer 1

2

You should use this:

start cmd.exe /k cd Folder1 ^& set prompt=Folder1: start cmd.exe /k cd Folder2 ^& set prompt=Folder2: start cmd.exe /k cd Folder3 ^& set prompt=Folder3: start cmd.exe /k cd Folder4 ^& set prompt=Folder4: 

Right now the & character is not escaped which causes it to view the second part of your command as a new command within the scope of startAll.bat

This causes your commands to be executed like this:

  1. start a new window, which inherits the old prompt
  2. cd to a folder in the new window
  3. set the prompt of the old window to the folder name
  4. go back to 1, however the prompt of the old window changed

which then causes your 4 new windows to have prompts like this:

  1. the old, original prompt, which is most likely the path to startAll.bat
  2. folder 1 (note that this is the window that cded into folder2

etc...

Sign up to request clarification or add additional context in comments.

2 Comments

@barakmanos added some explanation of what was going on. Next time when debugging a batch-file, make sure it doesn't have @echo off at the top and add a pause to the end.
Alternatively, you could put the command line after /k in between quotation marks: start cmd.exe /k "cd Folder1 & set prompt=Folder1:"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.