cross-platform launch command
a guest Oct 25th, 2012 303 Never
- import os
- import subprocess
- import sys
- def launch(program):
- Run program as if it had been double-clicked in Finder, Explorer,
- Nautilus, etc. On OS X, the program should be a .app bundle, not a
- UNIX executable. When used with a URL, a non-executable file, etc.,
- the behavior is implementation-defined.
- Returns something false (0 or None) on success; returns something
- True (e.g., an error code from open or xdg-open) or throws on failure.
- However, note that in some cases the command may succeed without
- actually launching the targeted program."""
- if sys.platform == 'darwin':
- ret = subprocess.call(['open', program])
- elif sys.platform.startswith('win'):
- ret = os.startfile(os.path.normpath(program))
- ret = subprocess.call(['xdg-open', program])
- return ret
RAW Paste Data