def _exists_in_path(cmd, environ):
 if (u'PATH' in environ):
  input_environ = environ.get(u'PATH')
 else:
  input_environ = os.environ.get(u'PATH', u'')
 extensions = os.environ.get(u'PATHEXT', u'').split(os.pathsep)
 for directory in input_environ.split(os.pathsep):
  base = os.path.join(directory, cmd)
  options = ([base] + [(base + ext) for ext in extensions])
  for filename in options:
   if os.path.exists(filename):
    return (True, filename)
 return (False, None)

def _exists_in_path ( cmd , environ ) : if ( u'PATH' in environ ) : input_environ = environ . get ( u'PATH' ) else : input_environ = os . environ . get ( u'PATH' , u'' ) extensions = os . environ . get ( u'PATHEXT' , u'' ) . split ( os . pathsep ) for directory in input_environ . split ( os . pathsep ) : base = os . path . join ( directory , cmd ) options = ( [ base ] + [ ( base + ext ) for ext in extensions ] ) for filename in options : if os . path . exists ( filename ) : return ( True , filename ) return ( False , None )
based on a code snippet from URL .