[Tutor] os.system

dman dsh8290@rit.edu
Sat, 17 Nov 2001 11:22:38 -0500


On Sat, Nov 17, 2001 at 05:07:45PM +0100, Hans Gubitz wrote:
| Hi,
| I want to display a picture on a remote host by
| os.system("xv -display host:0.0 picture.jpg")
| 
| system execute the command in a subshell.
| 
| I don't know how to close this  subshell!

The subshell will be closed when the program (xv) terminates.

If you want your program to not wait for it, use the following :


import os

pid = os.fork()
if pid == 0 :
    # this is the child
    os.execv( "xv" , ( "-display" , "host:0.0" , "picture.jpg" ) )
else :
    # this is the parent,
    # nothing special to do
    pass


This is what os.system() does, except that in the parent it waits for
the child to terminate.

HTH,
-D