python - Pass input to Popen process -
i cannot find proper solution following case. so, want pipe 2 shell commands, , pass input data (mypassword here) 2nd one. here's code demonstrating problem:
import subprocess import shlex args1 = shlex.split("find /home/vasya/rmps/ -name *.rpm") ps = subprocess.popen(args1, stdout=subprocess.pipe) args2 = shlex.split("xargs rpmsign --addsign") p2 = subprocess.popen(args2, stdin=ps.stdout, stdout=subprocess.pipe) ps.stdout.close() output = p2.communicate('mypassword\n')[0] print(output) when run asks in console: enter pass phrase: , stops despite fact passing pass phrase (my mypassword input).
where fault , how fix it?
your stdin xargs output of find, can't also input else.
one option write result of find file , use -a (--arg-file) option of xargs. allow input filenames while still keeping stdin free piped in python program (via communicate)
Comments
Post a Comment