How to eliminate consol window in MS Windows

Fredrik Lundh fredrik at pythonware.com
Thu Oct 28 02:59:53 EDT 1999


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