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?

Neil
  • 7,861
  • 4
  • 53
  • 74

3 Answers3

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 
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • Inheriting the current directory worked as expected and is perfect for my use case. Thanks. – Neil May 07 '13 at 08:53
  • In most contexts you can embed quoted commands inside in outer quote: `cmd /k ""prog 1.bat" % "prog 2.bat""` – Seth Dec 28 '16 at 15:50
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 
foxidrive
  • 40,353
  • 10
  • 53
  • 68
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:
ms_27
  • 1,484
  • 15
  • 22