subprocess module

John Mechaniks sn.oo.py.9027 at gmail.com
Mon Jul 14 12:05:56 CEST 2008


On Jul 14, 12:34 pm, Peter Otten <__pete... at web.de> wrote:
> John Mechaniks wrote:
> > from subprocess import call
> > call(['ls', '-l'])
>
> > How do I get the result (not the exit status of the command) of "ls -
> > l" into a variable?
>
> output = subprocess.Popen(["ls", "-l"], stdout=subprocess.PIPE).stdout.read()
>
> Peter

Thanks Peter.

Just curious

What difference does the following code makes? What are the advantages
of the above method over this one?
output = subprocess.Popen(['ls', '-l'],
stdout=subprocess.PIPE).communicate()[0]

Also could someone show an example of using the optional input
argument for communicate()




More information about the Python-list mailing list