[Tutor] Running an external command?
James.Rocks@equant.com
James.Rocks@equant.com
Fri, 11 Oct 2002 08:49:37 +0100
Hi Magnus, Hi Alan,
Alan:
> os.system()
> OR
> os.popen()
> Basically the second allows you to read the output of the
> program - which might be handy for a ping!
> Read the os module docs for the details.
Magnus:
> host = 'www.python.org'
> os.system('ping %s" % host)
> Will wait for the ping to finish.
> Obviously, if you want the output, your program
> must wait:
> resultList = os.popen('ping %s' % host).readlines()
> If you don't want your program to wait, you should
> run the following.
> Windows: os.system('start ping %s" % host)
> Unix: os.system('ping %s &" % host)
Brilliant (exactly what I wanted) ... thanks to both of you :-)
James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ