[Tutor] how to get response from os.system()

Nathan McBride nomb85 at comcast.net
Sun Mar 16 20:47:54 CET 2008

Would you mind perhaps show an example running an interactive command like su and show how to send input to the commands waiting propmts?

-----Original Message-----
From: linuxian iandsd <pylinuxian at gmail.com>
Sent: Sunday, March 16, 2008 3:17 PM
To: tutor at python.org
Subject: Re: [Tutor] how to get response from os.system()

i guess that was too short tutorial well, here is an example from a live
session on the interpreter.

[root at serv ~]# python
Python 2.5.1 (r251:54863, Nov 23 2007, 16:16:53)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> cmd='ping -c 1 localhost'
>>> import os
>>> a=os.popen(cmd)
>>> print a
<open file 'ping -c 1 localhost', mode 'r' at 0xb7f1c728>
>>> print a.read()
PING serv.kontactel.loc ( 56(84) bytes of data.
64 bytes from serv.kontactel.loc ( icmp_seq=1 ttl=64 time=0.134ms

[The entire original message is not included]

More information about the Tutor mailing list