Rob
Rob

Reputation: 1280

How to change color of new cmd window (together with a custom prompt) created via running a batch script

I already know how to create a new cmd window from a batch script with custom color, and a new cmd window with a custom prompt. However am wanting to find a way of combining the two together...

Here is what I have in my batch file to create a new cmd window with customised prompt (in this case, the customised prompt is the windows version details):

start cmd /k "prompt $v"

... And this is what I'm doing to create a new cmd window with customised color:

start cmd /k "color 42"

I've tried the following to combine the two, but none of them work:

start cmd /k "color 42" /k "prompt $v"

start cmd /k"color 42" "prompt $v"

If anyone can help point me in the right direction that would be awesome. Been searching via Google and other forums but after spending over an hour on a fruitless search I thought I'd ask a question here...

Upvotes: 5

Views: 8920

Answers (3)

Jason S
Jason S

Reputation: 189796

I'm late to the party here, but note that cmd /t:fg will set the colors just like the color command, so you could also run

start cmd /t:42 /k "prompt $v"

Upvotes: 0

dbenham
dbenham

Reputation: 130889

The only thing you are missing is the operator that will concatenate multiple commands on one line: &.

start cmd /k "color 42&prompt $v"

This operator works in all situations, not just within the command string for the CMD command. There are a few concatenation operators with different behavior:

  • & - Always executes the next command
  • && - Only executes the next command if the prior command was successful (ERRORLEVEL=0)
  • || - Only executes the next command if the prior command failed (ERRORLEVEL<>0)

Upvotes: 8

Maksym Polshcha
Maksym Polshcha

Reputation: 18368

try:

start cmd /k"color 42; prompt $v"

Upvotes: 0

Related Questions