Why it doesn't go ????

Gerhard Häring gh at ghaering.de
Fri Jun 6 14:39:06 CEST 2003

Panther wrote:
> import os
> fd = os.popen('python ping.py', 'r')
> if fd.readline() == 'None':
>  print "I'don't ping ip"

ping.py? Which ping.py are you talking about?

Or do you want to invoke the system command 'ping' instead? If you want 
to invoke the system command, this would look like:

fd = os.popen('ping', 'r')

No python and no .py.

Also it's hard for me to believe this program will actually print a line 
called 'None'.

To invoke the system 'ping', here's a suggestion:

import commands
output = commands.getoutput("ping -c 1")

Linux ping has a -c parameter for how often to ping. Similarly -n on 
Windows. Linux ping will ping until killed by default.


-- Gerhard

More information about the Python-list mailing list