How to change color of new cmd window (together wi

2019-07-01 10:15发布

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...

2条回答
时光不老,我们不散
2楼-- · 2019-07-01 10:30

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)
查看更多
叼着烟拽天下
3楼-- · 2019-07-01 10:30

try:

start cmd /k"color 42; prompt $v"
查看更多
登录 后发表回答