startfile() equivalent

Joe Koberg joe at osoft.us
Thu Aug 19 09:30:39 PDT 2004


Max Russell wrote:

>Also- I do not launch x-mame from the GUI, I use a
>script (in Perl) to select and choose my game of
>choice. So I suppose what I am looking for is
>something that allows me to use a *nix system command
>from within a Python script.
>
>  
>

http://www.python.org/doc/lib/os-process.html


If you just want to launch a command:
   
    import os
    os.system('unix shell command here')


If you need the stdin/stdout/stderr channels from the process you launched,
to communicate with it over stdio:

    import os
    stdin, stdout, stderr = os.popen3('unix shell command here')
    # now you can do i.e. stdin.write('data going to program')


If you want the new process to replace your python process (exec):

    import os
    os.execvp(programname, (arg1, arg2, arg3, ...))
    # os.execvp doesn't return - so you'll never reach this comment


If you want to start the process and wait around for its return value:
    import os
    returnval = os.spawnvp(os.P_WAIT, programname, (arg1, arg2, ...))


or if you want to start it and get its PID immediately:
    import os
    pid = os.spawnvp(os.P_NOWAIT, programname, (arg1, arg2, ...))



Thanks for using Python and FreeBSD!

Joe Koberg
joe at osoft dot us






More information about the freebsd-python mailing list