[Python] eseguire comandi shell/dos

Emanuele Santoro santoro.emanuele a gmail.com
Ven 13 Apr 2007 18:51:06 CEST


Il giorno mer, 11/04/2007 alle 22.45 +0200, Salvatore MONACO ha scritto:
> Ciao a tutti
> Non trovo il metodo per eseguire programmi esterni tipo il ifconfig, netstat
> dovrei poi catturare l'output...

manu a JoKeR:~$ python
Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) 
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help("os.system")

Help on built-in function system in os:

os.system = system(...)
    system(command) -> exit_status
    
    Execute the command (a string) in a subshell.

>>> help("os.popen")

Help on built-in function popen in os:

os.popen = popen(...)
    popen(command [, mode='r' [, bufsize]]) -> pipe
    
    Open a pipe to/from a command returning a file object.

>>> help("commands.getoutput")

Help on function getoutput in commands:

commands.getoutput = getoutput(cmd)
    Return output (stdout or stderr) of executing cmd in a shell.


Questi dovrebbero poter assecondare quasi tutte le tue necessitą.
Se non ci riescono, sono degli ottimi punti di partenza per ulteriori [ricerche|approfondimenti].

Buon divertimento,
Emanuele Santoro
-- 
manca qualcosa in me...
quel qualcosa che possa arricchire le mie giornate.
quel qualcosa che potrebbe rendermi pił sicuro,pił sereno.
quel qalcosa che potrebbe rendemi pił piacevole agli occhi degli
altri,ma prima di tutto a me stesso.
quel …



Maggiori informazioni sulla lista Python