Return the best path to the executable program with the provided name.
Favor vendor/bin in the current project. If not found there, use whatever
is on the $PATH.

@param string $cmd
The executable to find.

@return bool|string
559821
protected function findExecutable($cmd)
    {
        $pathToCmd = $this->searchForExecutable($cmd);
        if ($pathToCmd) {
            return $this->useCallOnWindows($pathToCmd);
        }
        return false;
    }
74433
def find_command(cmd, paths = [])
      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      paths += ENV['PATH'].split(File::PATH_SEPARATOR)
      paths.each do |path|
        exts.each do |ext|
          exe = File.join(path, "#{cmd}#{ext}")
          if (File.executable?(exe) && File.file?(exe))
            return Shellwords.escape exe
          end
        end
      end
      nil
    end
1167373
protected function executeCommand($cmd)
    {
        // Shell-escape all arguments except the command.
        $args = func_get_args();
        foreach ($args as $index => $arg) {
            if ($index !== 0) {
                $args[$index] = escapeshellarg($arg);
            }
        }

        // And replace the arguments.
        $command = call_user_func_array('sprintf', $args);
        $output = '';
        if ($this->io->isVerbose()) {
            $this->io->write('<comment>' . $command . '</comment>');
            $io = $this->io;
            $output = function ($type, $data) use ($io) {
                if ($type === Process::ERR) {
                    $io->write('<error>' . $data . '</error>');
                } else {
                    $io->write('<comment>' . $data . '</comment>');
                }
            };
        }
        return ($this->executor->execute($command, $output) === 0);
    }
1110629
protected function getPath()
	{
		$path = $this->input->getOption('path');

		if (is_null($path))
		{
			return $this->flyphp['path'].'/commands';
		}
		else
		{
			return $this->flyphp['path.base'].'/'.$path;
		}
	}
1275873
def find_command(cmd, path=None, pathext=None):
    
    if path is None:
        path = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(path, string_types):
        path = [path]

    # check if there are path extensions for Windows executables
    if pathext is None:
        pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
        pathext = pathext.split(os.pathsep)

    # don't use extensions if the command ends with one of them
    for ext in pathext:
        if cmd.endswith(ext):
            pathext = ['']
            break

    # check if we find the command on PATH
    for p in path:
        f = os.path.join(p, cmd)
        if os.path.isfile(f):
            return f
        for ext in pathext:
            fext = f + ext
            if os.path.isfile(fext):
                return fext
    return None
392406
public function getUrl(string $path, ?string $packageName = null): string
    {
        if ($this->status == self::NOT_LOADED) {
            $namedPackages = $this->getNamedPackages();
            if (empty($namedPackages)) {
                $this->package = $this->getDefaultPackage();
                $this->status = self::ONE_PACKAGE;
            } else {
                $defaultPackage = $this->getDefaultPackage();
                $this->packages = new Packages($defaultPackage, $namedPackages);
                $this->status = self::MUTI_PACKAGES;
            }
        }
        if ($this->status == self::ONE_PACKAGE) {
            return $this->package->getUrl($path);
        } else {
            return $this->packages->getUrl($path, $packageName);
        }
    }
1306288
def perl_cmd():
    
    perl = which(os.path.join(get_bcbio_bin(), "perl"))
    if perl:
        return perl
    else:
        return which("perl")
713790
protected function _getAbsoluteRemotePath($path = null)
    {
        if (null === $path) {
            return $this->_startingpath;
        }

        $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
        if (null === $parse_url = @parse_url($path)) {
            $parse_url = array('path' => $path);
        }

        return ('/' === substr($parse_url['path'], 0, 1) ? $path : $this->_remotepath.'/'.$path);
    }
413560
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
    

    if os.path.dirname(cmd):
        if os.path.isfile(cmd) and os.access(cmd, mode):
            return cmd

    if path is None:
        path = os.environ.get('PATH', defpath)
    if not path:
        return None

    paths = path.split(pathsep)

    if sys.platform == 'win32':
        # oh boy
        if curdir not in paths:
            paths = [curdir] + paths

        # also need to check the fileexts...
        pathext = os.environ.get('PATHEXT', '').split(pathsep)

        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]
        else:
            files = [cmd + ext for ext in pathext]
    else:
        # sanity
        files = [cmd]

    seen = set()
    for p in paths:
        normpath = normcase(p)
        if normpath in seen:
            continue
        seen.add(normpath)
        for f in files:
            fn = os.path.join(p, f)
            if os.path.isfile(fn) and os.access(fn, mode):
                return fn

    return None
848372
protected function getPath($name)
    {
        $name = $this->getFileName();

        $withName = boolval($this->option('name'));

        $path = $this->settings['path'];
        if ($this->settingsDirectoryNamespace() === true) {
            $path .= $this->getArgumentPath($withName);
        }

        $path .= $name;

        return $path;
    }
1341740
public function getComposerBinDir($path)
    {
        if (is_dir($path)) {
            $composer = $path.'/composer.json';
            if (is_file($composer)) {
                $json = json_decode(file_get_contents($composer));

                if (isset($json->config->{"bin-dir"})) {
                    return $path.'/'.$json->config->{"bin-dir"};
                } elseif (is_dir($path . '/vendor/bin')) {
                    return $path  . '/vendor/bin';
                }
            }
        }
        return null;
    }
911038
protected function _pipeline($cmd = null)
    {
        if (!isset($this->_temp['fetchob'])) {
            $this->_temp['fetchob'] = new Horde_Imap_Client_Fetch_Results(
                $this->_fetchDataClass,
                Horde_Imap_Client_Fetch_Results::SEQUENCE
            );
        }

        $ob = new Horde_Imap_Client_Interaction_Pipeline(
            clone $this->_temp['fetchob']
        );

        if (!is_null($cmd)) {
            $ob->add($cmd);
        }

        return $ob;
    }
962112
public function getCmsPath()
    {
        if ($this->composer->getPackage()) {
            $extra = $this->composer->getPackage()->getExtra();
            if (! empty($extra['cms-path'])) {
                return $extra['cms-path'];
            }
        }
        
        return 'thinkcms';
    }
1161941
private function getCLIPath()
    {
        $command = '';
        if (!is_null($this->path)) {
            $command .= sprintf(' -- %s', escapeshellarg($this->path));
        }
        return $command;
    }
64772
public static function findCommandLong($arg) {
		foreach (self::$commands as $command => $commandOptions) {
			if (($commandOptions["commandLong"] == $arg) || ($commandOptions["commandShort"] == $arg)) {
				return $command;
			}
		}
		return false;
	}
142150
async function resolveExecutablePath (cmd) {
  let executablePath;
  try {
    executablePath = await fs.which(cmd);
    if (executablePath && await fs.exists(executablePath)) {
      return executablePath;
    }
  } catch (err) {
    if ((/not found/gi).test(err.message)) {
      log.debug(err);
    } else {
      log.warn(err);
    }
  }
  log.debug(`No executable path of '${cmd}'.`);
  if (executablePath) {
    log.debug(`Does '${executablePath}' exist?`);
  }
  return null;
}
622314
public function commandmetaCallbackFunction(CommandInterface $cmd)
    {
        $cmdSignature = $cmd->getSignature();


        $buf = new Buffer;
        $buf->indent();

        $buf->appendLine("local curcontext=\$curcontext state line ret=1");
        $buf->appendLine("declare -A opt_args");
        $buf->appendLine("declare -A values");
        $buf->appendLine("local ret=1");

        /*
        values=$(example/demo meta commit arg 1 valid-values)
        _values "description" ${=values} && ret=0
        return ret
        */
        $buf->appendLine("local desc=\$1");
        $buf->appendLine("local valtype=\$3");
        $buf->appendLine("local pos=\$4");
        $buf->appendLine("local completion=\$5");

        $metaCommand = [$this->programName, 'meta', $cmdSignature, '$valtype', '$pos', '$completion'];
        $buf->appendLine('$(' . implode(" ", $metaCommand) . ')');
        $buf->appendLine('_values $desc ${=values} && ret=0'); // expand value array as arguments
        $buf->appendLine('return ret');

        $funcName = $this->commandFunctionName($cmdSignature);

        return $this->compFunction($funcName, $buf);
    }