# -*- coding: utf-8 -*-
"""
Created on 2015年8月9日

@author: lowitty
"""
import os


def cmd_executable(cmd):
    def is_exe(file):
        return os.path.isfile(file) and os.access(file, os.X_OK)
    
    cmdPath, cmdFile = os.path.split(cmd)
    if cmdPath:
        if(is_exe(cmd)):
            return cmd
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, cmd)
            if(is_exe(exe_file)):
                return exe_file
    return None
