On Thu, Jul 08, 2010 at 09:04:54AM -0400, Paul VanGundy wrote: > Hi All, > > I'm trying to get data from subprocess.Popen. To be specific, I am > trying to read a ping echo and take the output and assign it to a > variable like below: > > ping = subprocess.Popen("ping -c 5 %s" % (server), > stdout=subprocess.PIPE, shell=True)
>>> import subprocess >>> server = 'localhost' >>> ping = subprocess.Popen("ping -c 5 %s" % >>> (server),stdout=subprocess.PIPE, shell=True) >>> ping.communicate() ('PING localhost (127.0.0.1) 56(84) bytes of data.\n64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.044 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.046 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.052 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.046 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.049 ms\n\n--- localhost ping statistics ---\n5 packets transmitted, 5 received, 0% packet loss, time 3997ms\nrtt min/avg/max/mdev = 0.044/0.047/0.052/0.006 ms\n', None) >>> hth, With warm regards, -Payal -- _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor