How can i change the colour of a command window via batch script when using the start command

孤人 提交于 2020-01-05 12:34:22

问题


i am running a number of small batch scripts to copy data from one location to another using robocopy

i have pasted a sample below.

what i need to do for each of these batch files is get it to open and run the robocopy commands listed (which it is doing) but i need the robocopy output windows to be in set colours per batch file.

the batch file reads as below start robocopy.exe "source" "destination" /MIR /Log:e:\outputlog.txt /TEE

start robocopy.exe "source" "destination" /MIR /Log:e:\outputlog.txt /TEE

start robocopy.exe "source" "destination" /MIR /Log:e:\outputlog.txt /TEE

the above would all run at once which is fine but i cannot make the robocopy windows change colour. (the 3 above are fine as one colour we would run another batch file as above but with a different colour to differentiate between copies)

is this even possible.

i know the cmd command can have a colour change which works but only for that window. as the robocopy command opens up a new window the colour settings do not pass down,

any help or ideas on this would be greatly appreciated. we need to keep the code simple as various users need to use it


回答1:


cmd can take a /T parameter to specify the colours. Eg: start cmd /T:5A starts a new command windows with purple(5) background and light green text(A)

You can use /C or /K to start a new command within the new instance ( C terminates on completion)

i.e. start cmd /T:5A /K robocopy... should do it




回答2:


If you made the 2 separate robocopys into batch files you can change colours then.

---- bat1.cmd

color 71
robocopy.exe "source" "destination" /MIR /Log:e:\outputlog.txt /TEE

---- bat2.cmd

color 75
robocopy.exe "source" "destination" /MIR /Log:e:\outputlog.txt /TEE

then your original thing does

call bat1.cmd
call bat2.cmd

Does this not work for you?



来源:https://stackoverflow.com/questions/10349069/how-can-i-change-the-colour-of-a-command-window-via-batch-script-when-using-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!