问题
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