如何更改通过运行批处理脚本创建的新cmd窗口的颜色(以及自定义提示) [英] How to change color of new cmd window (together with a custom prompt) created via running a batch script
问题描述
我已经知道如何使用具有自定义颜色的批处理脚本和具有自定义提示的新cmd窗口创建新的cmd窗口.但是,我想找到一种将两者结合在一起的方法...
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...
这是我在批处理文件中创建的带有自定义提示的新cmd窗口的内容(在这种情况下,自定义提示是Windows版本的详细信息):
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"
...这就是我要创建具有自定义颜色的新cmd窗口的步骤:
... 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"
如果有人可以帮助我指出正确的方向,那就太好了.一直在通过Google和其他论坛进行搜索,但是花了一个多小时进行了毫无结果的搜索后,我想在这里问一个问题...
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...
推荐答案
唯一缺少的是运算符,它将在一行上连接多个命令:&
.
The only thing you are missing is the operator that will concatenate multiple commands on one line: &
.
start cmd /k "color 42&prompt $v"
此运算符可在所有情况下工作,而不仅限于CMD命令的命令字符串中.有一些具有不同行为的串联运算符:
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:
-
&
-始终执行下一条命令 -
&&
-仅在上一个命令成功执行(ERRORLEVEL = 0)时才执行下一个命令 -
||
-仅在先前命令失败(ERRORLEVEL<> 0)时执行下一条命令
&
- 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)
这篇关于如何更改通过运行批处理脚本创建的新cmd窗口的颜色(以及自定义提示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!