6

I am opening 3 cmd windows in different colours to help me distinguish between servers etc. These commands are in a .bat file.

start cmd /k color 4C
start cmd /k color 5D 
start cmd /k color 2A 

What I need to do is have them open up at a specific location but I can't seem to get it to chain commands.

How can I cd in to some folder structure immediately after starting a cmd window?

3 Answers 3

12

Use &:

start cmd /k "color 4C & cd \"

You have to quote the commands now, otherwise the & is consumed by the outer command prompt (e.g. the one running the batch file) rather than the newly launched one.


You also have another option - so far as I'm aware, a newly launched command prompt inherits the same current directory as the command prompt that launches it. So you could change your batch file to:

cd \location1
start cmd /k color 4C
cd \location2
start cmd /k color 5D 
cd \location3
start cmd /k color 2A 
Sign up to request clarification or add additional context in comments.

2 Comments

Inheriting the current directory worked as expected and is perfect for my use case. Thanks.
In most contexts you can embed quoted commands inside in outer quote: cmd /k ""prog 1.bat" % "prog 2.bat""
1
start "" /d "c:\foldera" cmd /k color 4C
start "" /d "c:\folderb" cmd /k color 5D 
start "" /d "c:\folderc" cmd /k color 2A 

1 Comment

Explanation...?
0

Try this code in a batch file. For 1st cmd prompt, provide the directory structure in place of "cd\". same goes for 2nd and 3rd cmd prompt at lines "d:" and "e:".

start cmd /k color 4C
REM following line for c:\ directory for 1st prompt
cd\

start cmd /k color 5D 
REM for any other directory for 2nd prompt
d:

start cmd /k color 2A
REM for another directory for 3rd prompt
e:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.