So I would like to grab stdout from a subprocess and then write the output to a file using python.
The problem I'm having is the stdout from the subprocess loses the formatting, it contains \n's where there are newlines. I would like to write the output to a file with formatting intact, meaning instead of one line containg \n's, the file contains newlines where there are \n's.
Here is my existing code:
import os, subprocess
from cStringIO import StringIO
proc = subprocess.Popen('foo.exe', shell=True, stdout=subprocess.PIPE,)
stdout_value = proc.communicate()[0]
f=open('fooOut.txt', 'w')
f.write(str(repr(stdout_value)))
f.close()
Current File Text: abbbb\nabbbb\naaaaab
What I would like:
abbbb
bbbb
aaaaab