According to the Python 3.5 docs, subprocess.run() returns an a CompletedProcess object with a stdout member that contains "A bytes sequence, or a string if run() was called with universal_newlines=True." I'm only seeing a byte sequence and not a string, which I was assuming (hoping) would be equivalent to a text line. For example,
import pprint
import subprocess
my_data = ""
line_count = 0
proc = subprocess.run(
args = [ 'cat', 'input.txt' ],
universal_newlines = True,
stdout = subprocess.PIPE)
for text_line in proc.stdout:
my_data += text_line
line_count += 1
word_file = open('output.txt', 'w')
pprint.pprint(my_data, word_file)
pprint.pprint(line_count, word_file)
Note: this uses a new feature in Python 3.5 that won't run in previous versions.
Do I need to create my own line buffering logic, or is there a way to get Python to do that for me?