#! python3 from subprocess import Popen, PIPE cmd = [ # command outputs binary file with many LFs ] with open('test', 'wb') as t: p = Popen(cmd, stdout=t) p.wait() # In file test, LFs are converted to CRLFs # Same problem when stdout=PIPE