subprocess.check_output (['cat', 'foo']) returns the string: "foo \ nbar"
Thus, the for loop repeats along the line, printing each character, one after the other.
The following should fix your problem:
import subprocess print subprocess.check_output(['cat', 'foo'])
You can also do:
import subprocess for line in subprocess.check_output(['cat', 'foo']).split('\n'): print "%r" % line
source share