#!/usr/bin/env python
import os
import os.path
"""
If the folder the program resides in is not added to the path the
program will naturally not run, since the executing environment have
no idea where it resides.
"""
if findprogram("mathlab")[0] == 1:
print "W00t"
else:
print "Oh noes!"
def findprogram(program):
path = os.environ['PATH']
paths = path.split(os.pathsep)
for d in paths:
if os.path.isdir(d):
fullpath = os.path.join(d, program)
if sys.platform[:3] == 'win':
for ext in '.exe', '.bat':
if os.path.isfile(fullpath + ext):
return 1, program_path
else:
if os.path.isfile(fullpath):
return 1, program_path
return 0, program + " command not found"