cancel
Showing results for 
Search instead for 
Did you mean: 

Suppress color from STM32_Programmer_CLI

JesperEC
Associate III

An old thread by @NVinc.1 on the subject: suppress color from STM32_Programmer_CLI - STMicroelectronics Community

This was never answered by anyone from ST, but I think it ST should track it as a feature request.

The suggested workaround to clean-up the output with sed or awk, is really only a band-aid.

On Linux, the tool should behave like other console programs and only emit color and other formatting ANSI escape-sequences if stdout and stderr (if used) is connected to a terminal.

It should behave that way on Windows too but I don't know enough about Windows development to say how technically feasible that is.

Finally, an standard option --color=WHEN where WHEN is always, auto or never would be good to take care of edge cases where detection doesn't work or you want to force coloring because the output is intended to be shown in a tool that can handle it. For example some job's console-output display in a CI runner.

   Best regards, Jesper

 

 

4 REPLIES 4
Pavel A.
Super User

IIRC cubeprogrammer_cli uses the Qt library, so search how to prevent Qt app from sending colored text. 

Try to pipe STM32_Programmer_CLI to a file, or thru "cat", to force the stdout device type non-tty: `STM32_Programmer_CLI > file` or  `STM32_Programmer_CLI | cat `

On Windows STM32_Programmer_CLI.exe outputs plain text when redirected to a file or pipe, without any color garbage.

For example: STM32_Programmer_CLI.exe .... | more -e

 

 

Hi @Pavel A. 

This is exactly how I would expect it to work. Redirection makes the output "not a tty".

May I please ask what version you tested with?

May our setup is just outdated.

    Best regards, Jesper

 

I've tested CLI from CubeProgrammer v 2.22.0 for Windows.

 

I have now tested 2.22.0.

On Window 11, it works as it should, just like Pavel A says. I have also tested 2.19.0 on Windows with the same positive result.

On Linux, it fails. Texted 2.19.0, 2.21.0 and 2.22.0.

 

STEPS TO REPRODUCE

1. Install STM32CubeProgrammer 2.22.0

2. cd <INSTALL_PATH>/bin

3. ./STM32_Programmer_CLI -v > /tmp/log

4. xxd -g 1 /tmp/log

 

EXPECTED BEHAVIOUR

/tmp/log contains only readable text.

 

ACTUAL BEHAVIOUR

The file contains text intermingled with ANSI escape codes:

00000000: 1b 5b 33 36 6d 1b 5b 30 31 6d 20 20 20 20 20 20 .[36m.[01m 
00000010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
00000020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
00000030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
00000040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
00000050: 2d 2d 2d 0a 1b 5b 33 39 3b 34 39 6d 1b 5b 30 6d ---..[39;49m.[0m
00000060: 1b 5b 33 36 6d 1b 5b 30 31 6d 20 20 20 20 20 20 .[36m.[01m
00000070: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
00000080: 20 20 53 54 4d 33 32 43 75 62 65 50 72 6f 67 72 STM32CubeProgr
00000090: 61 6d 6d 65 72 20 76 32 2e 32 32 2e 30 20 20 20 ammer v2.22.0

 

I have tested Ubuntu 22.04.5 LTS (which is the officially supported distribution according to STM32CubeProgrammer release v2.22.0 - Release note) and Debian GNU/Linux 12 (bookworm).

 

NOTES

Reasonably the program should call the C library's isatty() but from what I can see it does not.

Since it works on Windows I now consider this a bug and not a feature request.

Adding a  --color=WHEN is a feature request but should be low prio if tty-detection is made to work as expected.

If you don't want it to try to talk to the programmer you can use the actual print-version-only option which is --version instead of -v but the behaviour is the same.

    Best regards, Jesper

 

Announcement

We’re moving the ST Community to a new platform to give you a better and more reliable community experience.