Launching Programs on Windows
Suppose just for a moment, that you’ve been asked to write a big Python book, and want to provide a way for readers to easily start the book’s examples on just about any platform that Python runs on. Books are nice, but it’s awfully fun to be able to click on demos right away. That is, you want to write a general and portable launcher program in Python, for starting other Python programs. What to do?
In this chapter, we’ve seen how to portably spawn threads, but
these are simply parallel functions, not external programs.
We’ve also learned how to go about starting new, independently
running programs, with both the
exec combination, and
tools for launching shell commands such as
os.popen. Along the way, though, I’ve also
been careful to point out numerous times that the
os.fork call doesn’t work on Windows today,
os.popen fails in Python release 1.5.2 and
earlier when called from a GUI program on Windows; either of these
constraints may be improved by the time you read this book (e.g., 2.0
os.popen on Windows), but they
weren’t quite there yet as I wrote this chapter. Moreover, for
reasons we’ll explore later, the
call is prone to blocking (pausing) its caller in some scenarios.
Luckily, there are other ways to start programs in the Python standard library, albeit in platform-specific fashion:
os.spawnvecalls launch programs on Windows, much like a
execcall combination on Unix-like platforms.