[Tutor] XP & catching execl o/p ?

Dave S pythontut at pusspaws.net
Wed Dec 6 13:42:15 CET 2006


On Wednesday 06 December 2006 11:43, Dave S wrote:
> On Tuesday 05 December 2006 23:32, Alan Gauld wrote:
> > "Dave S" <pythontut at pusspaws.net> wrote
> >
> > > Struggling with python & XP again. My app needs to know if a certain
> > > program
> > > is running on my XP box
> > >
> > > os.execl('....')
> > > It throws the output to the terminal + I need the exact path to the
> > > executable
> > > (a bit of a trial)
> > >
> > > Any ideas how I can catch the output ?
> >
> > Look at the popen family of functions in the os module, and then
> > look at the subporocess module which supercedees them
> > (but the docs are expressed in tems of the oold functions!)
> >
> > Use subprocess because the older popen functions don't always
> > work reliably on Windows - there is a separate popen as part of
> > the winall package, but I think subprocess.Popen works Ok.
> >
> > There is more on this, including a simple example using subprocess,
> > in my OS topic in my tutorial.
> >
> > HTH,
>
> OK playing around I knocked up some test code ...
>
> #!/usr/bin/env python
> # -*- coding: iso8859_1 -*-
> import subprocess
>
> a = subprocess.Popen('tasklist.exe', bufsize=0, shell=False,
> stdout=subprocess.PIPE, stderr=None, stdin=None, universal_newlines=True)
> op = a.stdout.readlines()
> for i in op:
>     #print i
>     #print
>     pass
>
> #raw_input()
>
> This gives me what I need except when it runs windows flashes up a large
> black terminal window for a split second (yuk)
>
> This test would be performed while my app is running so thats not so good
> :)
>
> Any ideas on how to stop it displaying ?
>
> Dave


10 carrot idiot here :)

change from 
test.py
to 
test.pyw

:)

dave









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


More information about the Tutor mailing list