Reputation: 58951
I would like to use
subprocess.check_call(cmd)
with the stdin argument. Most tutorials I've found so far will recommend using Popen
directly (e.g., here), but I really need the exception if cmd
errors out.
Any hint on how to get
import subprocess
subprocess.check_call('patch -p1 < test.patch')
to work properly?
Upvotes: 1
Views: 1020
Reputation: 414915
There is no need to run the shell, you could pass a file object as stdin
:
with open('test.patch', 'rb', 0) as file:
subprocess.check_call(['patch', '-p1'], stdin=file)
Upvotes: 4
Reputation: 249652
Easy:
subprocess.check_call('patch -p1 < test.patch', shell=True)
Upvotes: 1