views:

36

answers:

1

Hi folks,

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

+3  A: 

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.

Ned Batchelder
@Ned thanks that was an awesome answer =D I'm going to try and capture the backspaces and bold the characters somehow
RadiantHex
@Ned hehe a little tricky
RadiantHex
@Ned came to write that re.sub() in the questions! Thanks you so much Ned! Mission accomplished =)
RadiantHex