On Apr 14, 2006, at 8:04 PM, david brochu jr wrote: > Thanks, > > Unfortunately substituting os.system with os.popen results in the > output being: > > <open file 'ping www.google.com > ', mode 'r' at 0x009C4650> > <open file 'ping www.boston.com > ', mode 'r' at 0x009C4650> > <open file 'ping www.espn.com > ', mode 'r' at 0x009C4650> > <open file 'ping www.redsox.com > ', mode 'r' at 0x009C4650> > > instead of giving me the ping stats "pinging etc etc, packets sent > 4 recienved 4 etc) > > Any idea around this?
os.popen gives you a file-like object that you can then read. >>> import os >>> f = os.popen('ping -c 5 www.google.com') >>> text = f.read() >>> print text PING www.l.google.com (64.233.167.147): 56 data bytes 64 bytes from 64.233.167.147: icmp_seq=0 ttl=241 time=20.855 ms 64 bytes from 64.233.167.147: icmp_seq=1 ttl=241 time=26.262 ms 64 bytes from 64.233.167.147: icmp_seq=2 ttl=241 time=22.300 ms 64 bytes from 64.233.167.147: icmp_seq=3 ttl=241 time=23.957 ms 64 bytes from 64.233.167.147: icmp_seq=4 ttl=241 time=22.056 ms --- www.l.google.com ping statistics --- 5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max/stddev = 20.855/23.086/26.262/1.871 ms >>> Dave -- http://mail.python.org/mailman/listinfo/python-list