-1

I am using Python to capture the output of Linux more. However, the file contains the characters:

<--- More --->^M ^M

How do I use Python to clean the lines? Or use more once more time to cleanit up?

user963986
  • 363
  • 1
  • 5
  • 10

1 Answers1

2

This isn't guaranteed to work, but you should try setting PAGER to cat in the environment of the child process. You can't do that with subprocess.call but you can do it with subprocess.Popen:

childenv = os.environ.copy()
childenv['PAGER'] = 'cat'

proc = subprocess.Popen(executable="yourprogram",
                        args=["yourprogram", ...],
                        env=childenv,
                        stdout=subprocess.PIPE,
                        ...)

# proc.stdout *may* now be free of `more` detritus
zwol
  • 135,547
  • 38
  • 252
  • 361