Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

cross-platform launch command

By: a guest on Oct 25th, 2012  |  syntax: Python  |  size: 0.84 KB  |  views: 260  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import os
  2. import subprocess
  3. import sys
  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.
  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 =['open', program])
  18.   elif sys.platform.startswith('win'):
  19.     ret = os.startfile(os.path.normpath(program))
  20.   else:
  21.     ret =['xdg-open', program])
  22.   return ret
clone this paste RAW Paste Data