Output from subprocess.Popen()

Fredrik Lundh fredrik at pythonware.com
Sun Oct 15 17:04:23 CEST 2006


Clodoaldo Pinto Neto wrote:

> Output from the shell:
> 
> [cpn at s0 teste]$ set | grep IFS
> IFS=$' \t\n'
> 
> Output from subprocess.Popen():
> 
>>>> import subprocess as sub
>>>> p = sub.Popen('set | grep IFS', shell=True, stdout=sub.PIPE)
>>>> p.stdout.readlines()[1]
> "IFS=' \t\n"
> 
> Both outputs for comparison:stdout=subprocess.PIPE)
> IFS=$' \t\n'
> "IFS=' \t\n"
> 
> The subprocess.Popen() output is missing the $ and the last '

if you expect one line of output, why are you doing readlines()[1] ?

 >>> f = subprocess.Popen("set | grep IFS", shell=True,
 >>> f.stdout.readlines()[1]
Traceback (most recent call last):
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
IndexError: list index out of range

this works for me:

 >>> f = subprocess.Popen("set | grep IFS", shell=True, 
stdout=subprocess.PIPE)
 >>> f.stdout.readlines()
["IFS=$' \\t\\n'\n"]

what does the above return on your machine?

</F>




More information about the Python-list mailing list