src/AbstractCmdTask.php
public static function checkCmd($cmd)
    {
        // cut out the actual executable part only
        // and leave args away
        $cmdParts = preg_split("/\s+/", $cmd);
        $cmd = $cmdParts[0];

        // try to find a command if not absolute path is given
        if (!preg_match('/^\.?\/.*$/', $cmd)) {
            $retval = null;
            $ouput = [];
            $fullCmd = exec("which $cmd", $output, $retval);
            if ($retval) {
                throw new InvalidArgumentException(sprintf("Failed to find full path for '%s'", $cmd));
            }
            $cmd = trim($fullCmd);
        }

        if (!file_exists($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' does not exist", $cmd));
        }

        if (!is_file($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' is not a file", $cmd));
        }
        if (!is_executable($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' is not executable", $cmd));
        }

        return true;
    }
public static function checkCmd($cmd)
    {
        // cut out the actual executable part only
        // and leave args away
        $cmdParts = preg_split("/\s+/", $cmd);
        $cmd = $cmdParts[0];

        // try to find a command if not absolute path is given
        if (!preg_match('/^\.?\/.*$/', $cmd)) {
            $retval = null;
            $ouput = [];
            $fullCmd = exec("which $cmd", $output, $retval);
            if ($retval) {
                throw new InvalidArgumentException(sprintf("Failed to find full path for '%s'", $cmd));
            }
            $cmd = trim($fullCmd);
        }

        if (!file_exists($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' does not exist", $cmd));
        }

        if (!is_file($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' is not a file", $cmd));
        }
        if (!is_executable($cmd)) {
            throw new InvalidArgumentException(sprintf("'%s' is not executable", $cmd));
        }

        return true;
    }
public static function checkCmd ( $ cmd ) { // cut out the actual executable part only // and leave args away $ cmdParts = preg_split ( "/\s+/" , $ cmd ) ; $ cmd = $ cmdParts [ 0 ] ; // try to find a command if not absolute path is given if ( ! preg_match ( '/^\.?\/.*$/' , $ cmd ) ) { $ retval = null ; $ ouput = [ ] ; $ fullCmd = exec ( "which $cmd" , $ output , $ retval ) ; if ( $ retval ) { throw new InvalidArgumentException ( sprintf ( "Failed to find full path for '%s'" , $ cmd ) ) ; } $ cmd = trim ( $ fullCmd ) ; } if ( ! file_exists ( $ cmd ) ) { throw new InvalidArgumentException ( sprintf ( "'%s' does not exist" , $ cmd ) ) ; } if ( ! is_file ( $ cmd ) ) { throw new InvalidArgumentException ( sprintf ( "'%s' is not a file" , $ cmd ) ) ; } if ( ! is_executable ( $ cmd ) ) { throw new InvalidArgumentException ( sprintf ( "'%s' is not executable" , $ cmd ) ) ; } return true ; }
Check if cmd exists and is an executable file
Check if cmd exists and is an executable file