Reputation: 649
I know that this question may have been asked a lot but I am still not really getting it.
Reading from this related link, I can understand why there is a need to add stdout=subprocess.PIPE
at the end of the sentence so that the output result can be used into the next Popen.
Tried looking online, but I garner little to no knowledge about it as the ones I found are in the form of a documentation.
But if I am not using the output, is it really necessary to put stdout=subprocess.PIPE
at the end?
I tried executing it with and without the use of it, and it is still giving me the expected results that I wanted.
Hence what are the big differences whether subprocess.PIPE
is present or not?
process = subprocess.Popen(command, stdout=subprocess.PIPE)
process.communicate()
Upvotes: 5
Views: 10062
Reputation: 414207
If you don't read/write to the corresponding pipe then you should not use subprocess.PIPE
. It may stall the child process if the corresponding OS pipe buffer fills up.
Use subprocess.PIPE
if you want to get the output of the child process (or pass input) as a string (variable) or just call subprocess.check_output()
that does it for you internally.
Use subprocess.PIPE
if you want to pass process.stdout
as stdin to another process (to emulate a | b
shell command).
If you want to ignore the output; you could redirect it to DEVNULL. You could redirect it to a file (or to anything with a valid .fileno()
e.g., sockets on Unix).
Upvotes: 3
Reputation: 65
Without subprocess.PIPE the output of command would be printed on STDOUT and process.communicate() should return None. Which python version are you using?
Can you paste the output?
Upvotes: 7