the windows equivalent of fork()?

DataJockey DataJockey at
Sat Mar 18 22:38:08 CET 2000

I am looking for a way to use the following functionallity in windows.
import os

def spawn(prog, *args):
    pipe1 = os.pipe()
    pipe2 = os.pipe()
    pid = os.fork()
    if pid:
        os.dup2(pipe1[0], 0)
        os.dup2(pipe2[1], 1)

        os.dup2(pipe2[0], 0)
        os.dup2(pipe1[1], 1)
        args = (prog,) + args
        os.execv(prog, args)


if is run this i get an 'AttributeError: fork'  that i understand,
fork() is a unix specific call.  however i do not know how to achieve
the same functionallity with windows.

i reference and i

spawnv (mode, path, args)
with constants for mode:
however if i try this
        os.spawnv(P_WAIT, 'C:\WINDOWS\Cdplayer.exe')
    the result is a NameError: P_WAIT
        os.spawnv('P_WAIT', 'C:\WINDOWS\Cdplayer.exe')
    the result is TypeError: 3-sequence, 2-sequence
            i do not know what this means, sorry

system (command)
        if i try os.system('os.execl("C:\WINDOWS\Cdplayer.exe")')
    a shell spawns and then exits, i get a result of 0 in the

in my books i have found that there is a command os.popen() should
automatically do the same as the above code spawn() from  i can
not find popen()'s defenition in the modules.  there is a, but
the code in this file uses fork(), so i am assuming that the fork() call
is causing the following errors.

if i do os.popen('') to spawn a shell, the result
    OSError: (0, 'Error')
if i do os.popen('os.execl("C:\WINDOWS\Cdplayer.exe")')
    OSError: (0, 'Error')

and finally if i just do os.execl("C:\WINDOWS\Cdplayer.exe")
python will preform an illegal op and exit, but it will open the cd

i hope someone can help :)
i am new to python and i love it.
i have learned a lot by playing with python, and i can usually figure
out my problems. but this one i can not, please help.

if you read this far, you rock!

thanks in advance
jens page

More information about the Python-list mailing list