[PIPython] os.system

Valentino Volonghi aka Dialtone dialtone
Gio 23 Giu 2005 19:20:35 CEST


Giovanni Dall'Olio wrote:

>Come si cattura l'output di questa funzione?
>Ad esempio, a=os.system('ls') mi stampa su schermo il contenuto della
>  
>
Da python 2.4:
import subprocess
help(subprocess)

In [5]:output = subprocess.Popen(["ls", "-l"],
stdout=subprocess.PIPE).communicate()[0]

In [6]:output
Out[6]:'total 184\n-rw-r--r--   1 dialtone  admin   3163 Dec 29 03:51
README.txt\n-rwxr-xr-x   1 dialtone  admin    772 Dec 29 03:51
TODO.txt\n-rw-r--r--   1 dialtone  admin  49833 Dec 29 03:51
modulegraph.zip\ndrwxr-xr-x   7 dialtone  admin    238 Dec 29 03:51
ntsvc\n-rwxr-xr-x   1 dialtone  admin    766 Dec 29 03:51
pysvc.ico\n-rw-r--r--   1 dialtone  admin    799 Dec 29 03:51
serviceinfo.ini\n-rw-r--r--   1 dialtone  admin  21751 Dec 29 03:51
tpusage.py\n'

altrimenti dovrai usare popen2

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4.1
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de



More information about the Python mailing list