While running Robot Framework tests on Ubuntu 22.04, the log/output files are getting cluttered with unwanted prefixes like ?[2004h, ubuntu@k8master2:~$ at the beginning of each line.
This seems to be coming from the terminal prompt or escape sequences being captured into the logs.
Has anyone encountered this? How can I suppress or remove these prefixes from the output/log files?
Those codes you see are “ANSI” codes. Typical way prevent those is to set TERM environment variable to dumb. However, i think this would not work for prompt since prompt is just a string that gets shown and there’s logic to sniff if the terminal supports colours or not.
In SSHLibrary, you can pass “term_type=dumb” to address most of the ansi codes to not be shown in the logs but setting the prompt might not be straight forward as the promt is typically set in initial login scripts that reside in the remote host that are sourced for interactive shells.
Easiest way would be to run something like export PS1='[\u@\h \W]\$ ' as first command but even in this case you would probably see the initial prompt with ansi codes but not from that point on if you remain within same shell instance.
As alternative, you could modify the script that gets loaded when shell starts by checking what is TERM value, if its dumb, modify the PS1 accordingly.