Using python to run another program?

subprocess.Popen expects an array of strings. Two of the items in that array are file handles. You need to pass the actual file name to the program you're trying to run.

cmd = ['/Users/me/src/program', 'a.txt', 'b.txt']

You can get rid of the with open(...) as ... lines completely.


Look at @Chris's answer, and also:

Subprocess doesn't wait for command to finish, so you should use wait method.

process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
process.wait()
for line in process.stdout:
    print(line)