[Tutor] Python question for beginners...

Doug Stanfield DOUGS@oceanic.com
Wed, 25 Aug 1999 08:00:27 -1000


Look at the os.popen command:
http://www.python.org/doc/current/lib/os-newstreams.html#l2h-819.

An example use:

def snmp_get(host,community="public",node="system.1.0"):
    command = "snmpget %s %s %s" % (host, community, node)
    answer = os.popen(command, 'r').readlines()
    return answer[0]

-Doug-

> -----Original Message-----
> From: Mark C. Mason [mailto:markm@lineo.com]
> Sent: Wednesday, August 25, 1999 7:39 AM
> To: tutor@python.org
> Subject: [Tutor] Python question for beginners...
> 
> 
> I am doing a cgi script.  I need the script to execute a program and
> return the program output as a variable preferably.
> I tried using os.system("/usr/local/bin/program") but that 
> doesn't seem
> to work from within the script.  It works in the python interpretor
> directly, but
> not within the script.  Maybe the os.execv command???I don't 
> know how to
> use that.
> any help would be greatly appreciated...
> 
> Mark
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>