I am using the following function to run a command in Python:
def run_proc(cmd):
child = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = child.communicate()
returncode = child.returncode
return stdout, stderr, returncode
It has always been working fine, however now I'm trying to use the yes
program to pipe output to stdin. The command I'm trying to run is the following:
yes '' | apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
but I believe it could be substituted with a general example, like:
yes | head -3 | cat
My problem is that if I try to run any command which has yes |
in it, the above subprocess.Popen will contain the error messages:
yes: standard output: Broken pipe
yes: write error
For me it seems that the piping still works, as can be seen from yes | head -3 | cat
's answer: y y y
.
I have the following questions:
- Is the yes piping still functional, even though yes reports error?
- How can I fix it?
yes
,SIGPIPE
, andEPIPE
– Justinajustine