RadiantHex
RadiantHex

Reputation: 25577

Using popen, but text looks weird - Python

I'm using os.popen() in order to run a few commands.

This is what "man ls" looks like:

alt text


Any ideas why the text is displayed as such. I tried both Arial and Consolas fonts.

Help would be amazing! Thanks

Upvotes: 0

Views: 253

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375854

Those are backspace characters: man is trying to backspace and reprint characters to get bolding, or underscores plus backspaces to get underlining.

The man man page says:

To get a plain text version of a man page, without backspaces and underscores, try

# man foo | col -b > foo.mantxt

You could also do a simple post-processing in Python:

s = re.sub(".\x08", "", s)

This removes any pair of characters where the second character is a backspace.

Upvotes: 3

Related Questions