ping

David Reed dreedmac at columbus.rr.com
Fri Apr 14 18:50:31 EDT 2006


On Apr 14, 2006, at 6:30 PM, david brochu jr wrote:

> I am trying to ping websites and output the results to a txt file:
>
> import os
>
> file = open("c:\python24\scripts\ip.txt")
> redirect = open("c:\python24\scripts\log.txt","a")
>
> for x in file:
>  ping = "ping " + x
>  print >> redirect, os.system(ping)
>
>
> but the results seen in the log.txt file are:
>
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
>
>
> What am i doing wrong?? How do I fix this so I can see the ping  
> statistics inside the log.txt file?

os.system does not return the output of the command. Look at os.popen.

Dave




More information about the Python-list mailing list