Why does shell=True eat my subprocess.Popen stdout?
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Why Does Shell=True Eat My Subprocess.Popen Stdout?
00:34 Accepted Answer Score 19
01:08 Thank you
--
Full question
https://stackoverflow.com/questions/1066...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #subprocess #pipe #popen
#avk47
    Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Why Does Shell=True Eat My Subprocess.Popen Stdout?
00:34 Accepted Answer Score 19
01:08 Thank you
--
Full question
https://stackoverflow.com/questions/1066...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #subprocess #pipe #popen
#avk47
ACCEPTED ANSWER
Score 19
When you pass shell=True, Popen expects a single string argument, not a list.  So when you do this:
p1 = Popen(['echo','hello'], stdout=PIPE, shell=True)
What happens is this:
execve("/bin/sh", ["/bin/sh", "-c", "echo", "hello"], ...)
That is, it calls sh -c "echo", and hello is effectively ignored (technically it becomes a positional argument to the shell).  So the shell runs echo, which prints \n, which is why you see that in your output.
If you use shell=True, you need to do this:
p1 = Popen('echo hello', stdout=PIPE, shell=True)