[Tutor] script ?

Alan Gauld alan.gauld at btinternet.com
Tue Oct 30 00:15:33 CET 2007


"Dan Freeman" <danrfreeman at gmail.com> wrote

> How can I have this script exucute a .exe file instead of beeping 
> the system
> speaker?

The same way you ran netstat - which is an .exe...

Of course, nowadays you probably should be using
subprocess.Popen instead os os.popen, but thats a minor tik.
Also if you don't need the output returned you could try
subprocess.call() (or on older systems os.system())

You'll find more discussion of this with examples in the
OS topic of my tutorial, near the end.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

> __________________________________________
>
> import os
> import time
>
> z = 2
>
> while z ==2:
>
>    connected = False
>    while not connected:
>        o=os.popen("netstat -an")

Here is an exe being run...

>        for l in o:
>            try:
>                if l.split()[1].endswith("159.215.49.8.116:59999"):
>                    print "\a\a\a\a\aMatch!"
>                    connected = True
>                else:
>                    print "Nothing"
>            except IndexError:
>                print "Index Exception"
>        time.sleep(1)
>
>    amount=0
>    while connected:
>        o=os.popen("netstat -an")
>        for l in o:
>            try:
>                if l.split()[1].endswith("159.215.49.8:59999"):
>                    print "Still There"
>                    connected = True
>                    amount +=1
>                    print amount
>                else:
>                    print "Nothing"
>            except IndexError:
>                print "Index Exception"
>        time.sleep(1)
>        if amount == 1:
>            amount -=1
>        else:
>            print "It's Gone"
>            connected = False
>
>    print "\a\a"
>
> raw_input("Press Enter to close")
>


--------------------------------------------------------------------------------


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list