I am using subprocess to run a command (from a spawned daemon) and trying to write results to a file. The resulting string from Popen is bytestring. How do I format this into something human readable before writing to a file? using python3.2
have tried:
print (x,file=o)
f.write(str(rc.so))
print (str(rc.so) + "\n")
Nothing ends up looking readable ..
suspect code:
rc = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
x = rc.stdout.readlines()
rc.so, rc.se = rc.communicate()
with open(of,'w') as o, open(ef,'w') as e:
print (str(rc.so) + "\n",file=o)
you need to decode it:
utf-8 might not be the best choice of decoding for your situation, it is one of a number of options available.
so that print statement should be more like: