2

I would like to display coloured output only for a partcular line.
Below is the code which works fine when run on cygwin:
echo -e '\e[0;31m' "Something failed"'\e[0m'
It displays the output properly with red color.


Now i would like to invoke the windows cmd prompt and generate the same output.
I would like to do the same thing using "cmd /c " option. But it does not work.
Below is the code of what i am trying to achieve as i am invoking from cygwin.

cmd /c echo -e '\e[0;31m' "Something failed"'\e[0m'
It does not produce colored output . I also tried using bin/echo but it still fails to display the red coloured output.

Is there any way through which i can achieve the red coloured output by invoking cmd /c from cygwin?

user9148262
  • 63
  • 1
  • 8

1 Answers1

0

Yes there are ways, but your code can't work, as echo -e .. will be executed with cmd.exe and the windows version of echo doesn't support -e.

You can build your own echo-e function or batch file for this.

echo-e.bat from echo -e equivalent in Windows?

@echo off
set "arg1=%~1"
set "arg1=%arg1:\x=0x%"
set "arg1=%arg1:\e=0x1B%"
forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%arg1%"

Then you could use it like

cmd /c echo-e "\e[0;31m Something failed\e[0m"

Note:
This only works when you start this from a mintty window.
When your code is running in a cmd-window, starting a cygwin script, starting the cmd /c echo-e ... it will only work in win10 with vt100 support

jeb
  • 78,592
  • 17
  • 171
  • 225