os.popen() and (IDLE, PythonWin) ?

Fredrik Lundh fredrik at pythonware.com
Tue Nov 2 03:57:48 EST 1999


M.-A. Lemburg <mal at lemburg.com> wrote:
> Ok, but how can I prevent the shell windows
> from popping up ? I read something about os.spawnv() in the docs,
> but the mode argument remains a complete mystery and I always
> get IOErrors about files not being found...

recently seen on c.l.py:

Subject: Re: How to eliminate consol window in MS Windows
Date: Thu, 28 Oct 1999 08:59:53 +0200

Radovan Garabik <garabik at center.fmph.uniba.sk.spam> wrote:
> and what is worse, the program does not run in the background
> I'd really like to use 
> os.spawnv(os.P_NOWAIT, "program.pyw", ("program.pyw", args))
> but it does not work at all... am I missing something?
> (I tried with the whole path, still nothing....)
> (note: I know next to nothing about programming under MS windows.. I am
> trying to do a quick port of my unix script)

you could try something like:

file = r"\full\path\pythonw.exe"
os.spawnv(os.P_NOWAIT, file, (file, "program.pyw") + tuple(args))

note that spawnv doesn't scan the path, and that
you need to pass the name of the excutable as the
first item in the argument tuple.

the following sample script from the eff-bot guide
shows one way to locate the executable:

# File: os-spawn-example-2.py

import os
import string

def run(program, *args, **kw):
    # find executable
    mode = kw.get("mode", os.P_WAIT)
    for path in string.split(os.environ["PATH"], os.pathsep):
        file = os.path.join(path, program) + ".exe"
        try:
            return os.spawnv(mode, file, (file,) + args)
        except os.error:
            pass
    raise os.error, "cannot find executable"

run("python", "hello.py", mode=os.P_NOWAIT)
print "goodbye"

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list