1. import os
  2. import subprocess
  3. import sys
  4.  
  5. def launch(program):
  6.   """launch(program)
  7.    Run program as if it had been double-clicked in Finder, Explorer,
  8.    Nautilus, etc. On OS X, the program should be a .app bundle, not a
  9.    UNIX executable. When used with a URL, a non-executable file, etc.,
  10.    the behavior is implementation-defined.
  11.    
  12.    Returns something false (0 or None) on success; returns something
  13.    True (e.g., an error code from open or xdg-open) or throws on failure.
  14.    However, note that in some cases the command may succeed without
  15.    actually launching the targeted program."""
  16.   if sys.platform == 'darwin':
  17.     ret = subprocess.call(['open', program])
  18.   elif sys.platform.startswith('win'):
  19.     ret = os.startfile(os.path.normpath(program))
  20.   else:
  21.     ret = subprocess.call(['xdg-open', program])
  22.   return ret