[Python-Dev] Fork on Win32 - was (test_fork1 failing...)

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Fri, 28 Jul 2000 20:33:38 +0200


mal wrote:
> BTW, (pardon my ignorance) what is the most portable way to
> do the equivalent of a os.system("cmd &") as native OS
> API call ? [On Unix, "cmd &" starts a new process which runs
> in the background and detached from the calling process.]
>=20
> I've looked at .execve and .spawnve, but they both replace
> the current process.

on windows, spawn(P_NOWAIT) does what you want.  here's
an example from the eff-bot guide:

#
# os-spawn-example-2.py

import os
import string

def run(program, *args, **kw):
    # find executable
    mode =3D kw.get("mode", os.P_WAIT)
    for path in string.split(os.environ["PATH"], os.pathsep):
        file =3D 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=3Dos.P_NOWAIT)

</F>