How do you execute an OS X application (bundle) from Python?

David Hughes dfh at
Fri Nov 5 17:17:03 CET 2004

aleaxit at (Alex Martelli) wrote 
> has <has.temp2 at> wrote:
> > > For example, in Python in a Nutshell, Alex Martelli shows how you can
> > > run a Windows (notepad.exe) or Unix-like (/bin/vim) text editor using
> > >       os.spawnv(os.P_WAIT, editor, [textfile])
> > > But how would you call the OS X text editor /Applications/
> > > - which appears to be a whole directory inside /Applications?
> > 
> > Using os.system to execute open is pretty simple, as other folks have
> > pointed out.
> ...but doesn't do the P_WAIT: just like using open at the Terminal
> prompt, it immediately continues with your code even as TextEdit is
> starting up.  The idea of that snippet is to let the user edit a
> textfile for configuration, while until the user is done editing, then
> read the textfile etc etc.  And it works file on the Mac with vi too.
> But apparently the P_WAIT is not implemented in the Mac version of
> Python like on the Windows version -- to *WAIT* until the app is done
> before continuing.  So, it looks as if one will have to put in more
> complicated code in that case:-(.

I don't know if that will be possible. The reason for my original
query was that I want to fire up an independent help viewer from an
application - both of which will be bundle-built. In fact, I *don't*
want to implement a wait, but I do want to use Popen from the
subprocess module to launch the viewer - so that I can use its poll()
method to check if it is already running should another launch be
requested, and also kill it on exit from the main application. But,
unlike Windows, poll() always returns a completion code of zero,
instead of None, even though the process is still running.


More information about the Python-list mailing list