0

I tried to execute a command using pexpect module and directed the result to a text file.

While appending the text it includes some weird characters in the text file.

This occurs when i tried to use ctrl command in the python script.

Here is the text appended to the file (See Bold char). Please provide me a solution.

[1m configPortConnection ........ [0m< slot connectMode >

[1m cpldReg ..................... [0m< op address data >

Actual text should be like this:

configPortConnection ........ < slot connectMode >

cpldReg ..................... < op address data >

Thanks

Alex
  • 111
  • 1
  • 2
  • 11
  • Those are escape codes, probably for coloring text in the console. – MattDMo Sep 04 '15 at 23:52
  • How can I remove those codes when I append text to a file? – Alex Sep 04 '15 at 23:55
  • 1
    Check out: http://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python or http://stackoverflow.com/questions/13506033/filtering-out-ansi-escape-sequences, or even http://unix.stackexchange.com/questions/4527/program-that-passes-stdin-to-stdout-with-color-codes-stripped. These are all various ways to strip ANSI escape sequences. – Seth Sep 05 '15 at 00:07
  • What command are you executing? It might be possible to turn off colour codes, e.g. for `grep` there is the `--color=never` option. – mhawke Sep 05 '15 at 00:20

0 Answers0