2

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?

4
  • Why not just use Powershell. Then you could format the prompt however you wanted in the profile.
    – EBGreen
    Oct 17, 2013 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 Oct 17, 2013 at 20:37
  • @EBGreen - I'll give that a try. Oct 18, 2013 at 12:53
  • @DavidRuhmann - Just tried your suggestion, but I still get the same error. Oct 18, 2013 at 12:54

2 Answers 2

0

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
1
  • I still receive the same error. Oct 18, 2013 at 12:53
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .