os.system question

Jay O'Connor joconnor at nets.com
Tue Jun 3 11:34:06 EDT 2003


In article <mailman.1054634944.13754.python-list at python.org>, "Ruslan
Spivak" <alienoid at is.lg.ua> wrote:

> Hello, python users!
> 
> 
> I need to get result from 'ping' command(in manpage they are 0, 1, 2),
> but when i execute the following lines i i get strange results:
> 
> import os
> 
> res = os.system("ping -w 3 192.168.1.1") print res
> 
> This gives 256 or another numbers, what am i doing wrong?

Try using 'commands' instead


	import commands

	status, output = commands.getstatusoutput ("ping...")


status will hold the exit status of the ping command.

I use it with '-c 1' to just ping once and return and status will hold a
0 if suceess.  output holds a string of pings output that I guess you
could parse.

For more info: http://www.python.org/doc/current/lib/module-commands.html

-- 
Jay O'Connor
http://www.r4h-music.com

"God Himself plays the bass strings first,
when He tunes the soul"




More information about the Python-list mailing list