I am attempting to make a colored command prompt in Windows 7.

Using ansicon, I have successfully managed to create the prompt. However, when I put the commands into a batch file, I receive an error.

These are the commands that I am using:

ansicon -p
chcp 65001
prompt $e[1;31m█$e[1;32m█$e[1;34m█$e[1;33m$_$d $t$_$e[1;37m$p$g

Below is an image that shows the contents and execution of the batch file, and the error that occurs when executing the prompt command within the batch file. It also shows the manual execution of the commands, and the resulting command prompt.

Ansicon batch failure

How can I get the commands to properly execute from a batch file?

  • Why not just use Powershell. Then you could format the prompt however you wanted in the profile. – EBGreen Oct 17 '13 at 15:24
  • My guess is that ansicon is failing to hook into the cmd.exe process for the batch file execution. -p What happens when you run ansicon -p on the command line and then run the bat file containing the chcp and prompt commands? ANSICON Documentation – David Ruhmann Oct 17 '13 at 20:37
  • @EBGreen - I'll give that a try. – Welton v3.59 Oct 18 '13 at 12:53
  • @DavidRuhmann - Just tried your suggestion, but I still get the same error. – Welton v3.59 Oct 18 '13 at 12:54

I've never used ansicon, and I don't know why your batch script is giving different behavior then the command line.

But give this a try in your batch script:

ansicon -p
chcp 65001
for /f "delims=" %%A in ("$e[1;31m█$e[1;32m█$e[1;34m█$e[1;33m$_$d $t$_$e[1;37m$p$g") do prompt %%A
  • I still receive the same error. – Welton v3.59 Oct 18 '13 at 12:53

I was unable to get the batch file to work correctly, so I ended up taking @EBGreen's suggestion and using PowerShell. I did have to run the command Set-ExecutionPolicy RemoteSigned in PowerShell to get my profile to run, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.