1

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?

Community
  • 1
  • 1
Nico Schlömer
  • 46,467
  • 24
  • 178
  • 218

2 Answers2

3

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)
jfs
  • 374,366
  • 172
  • 933
  • 1,594
1

Easy:

subprocess.check_call('patch -p1 < test.patch', shell=True)
John Zwinck
  • 223,042
  • 33
  • 293
  • 407