[Tutor] independent process

Magnus Lycka magnus@thinkware.se
Wed Oct 23 04:20:03 2002


At 16:47 2002-10-23 +0930, BELSEY, Dylan wrote:
>OK, I have just been shown a possible solution to this problem.
>
>         os.system("start %s" %(self.DB_GUI))
>
>         Using "start" will create an independent process in DOS/Windows
>systems.  However, is there a Python, platform independent way of doing
>this.  I am also open to any other solutions that people may have.

Not that I know of. If you look at section 6.1 of the library
reference, you'll see that things like os.fork() is only
available in unix etc.

In unix and friends you would change "start %s" to "%s &". I
don't know about MacOS. I suppose MacOSX works just as unix,
but I don't suppose that works with previous versions.

I reasonable approximation might be (untested):

import os
def runDetached(cmd):
     try:
         fmt =3D {'nt': 'start %s',
                'posix': '%s &'}[os.name]
     except KeyError:
         fmt =3D "%s"
     os.system(fmt % cmd)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se