Subprocess with and without shell

George Sakkis george.sakkis at gmail.com
Tue May 15 08:57:14 EDT 2007


On May 15, 5:30 am, Nick Craig-Wood <n... at craig-wood.com> wrote:

> George Sakkis <george.sak... at gmail.com> wrote:
> >  I'm trying to figure out why Popen captures the stderr of a specific
> >  command when it runs through the shell but not without it. IOW:
>
> >  cmd = [my_exe, arg1, arg2, ..., argN]
> >  if 1: # this captures both stdout and stderr as expected
> >      pipe = Popen(' '.join(cmd), shell=True, stderr=PIPE, stdout=PIPE)
> >  else: # this captures only stdout
> >      pipe = Popen(cmd, shell=False, stderr=PIPE, stdout=PIPE)
>
> >  # this prints the empty string if not run through the shell
> >  print "stderr:", pipe.stderr.read()
> >  # this prints correctly in both cases
> >  print "stdout:", pipe.stdout.read()
>
> >  Any hints ?
>
> Post an example which replicates the problem!

I would, but the specific executable being spawned is not a python
script, it's a compiled binary (it's not an extension module either;
it's totally unrelated to python). I don't claim there is a bug or
anything suspicious about Popen, but rather I'd like an explanation of
how can a program display different behavior depending on whether it
runs through the shell or not.

George





More information about the Python-list mailing list