Why it doesn't go ????

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


Panther wrote:
> import os
> fd = os.popen('python ping.py 192.168.1.4', '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 192.168.1.4', '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 192.168.1.4")

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

HTH,

-- Gerhard






More information about the Python-list mailing list