Shell Execute on Multiple Platforms
Need to execute shell commands on multiple platforms? Trying to execute a command to activate pdf viewer on a system regardless of the OS is incredibly simple.
pdf_file_path = doc_path + '/' +
outfile + '.pdf'
sys_plfrm = platform.system()
cmd = {'Darwin' :'open ',
'Windows':'start ',
'Linux' :'xpdf '}
try:
call([cmd[sys_pltfrm] + pdf_file_path], shell=True)
except OSError as err:
sys.exit('Error opening pdf:\n\t{}'.format(err))
I realize that having shell=True is not the safest with 'unsanitized' input
Nothing fancy, but a neat example for multi-system use...
Written by Daniel Chauvin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#