Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better windows support for pake_which calls #19

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions lib/pake/pakeFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,17 @@ function pake_chmod($arg, $target_dir, $mode, $umask = 0000)
function pake_which($cmd)
{
if (!isset($_SERVER['PATH']))
throw new pakeException('PATH environment variable is not set');
{
// win cli
if (!isset($_SERVER['Path']))
{
throw new pakeException('PATH environment variable is not set' );
}
else
{
$_SERVER['PATH'] = $_SERVER['Path'];
}
}

$paths = explode(PATH_SEPARATOR, $_SERVER['PATH']);

Expand All @@ -350,9 +360,26 @@ function pake_which($cmd)
}

$test = $path.'/'.$cmd;
if (file_exists($test) and !is_dir($test) and is_executable($test)) {
// nb: on win, executable bit does not need to be set
if (file_exists($test) and (is_executable($test) || strtolower(substr(PHP_OS, 0, 3)) == 'win')) {
return $test;
}
if ( strtolower(substr(PHP_OS, 0, 3)) == 'win') {
/// @todo we could probbaly get the list of known command suffixes from env, too
$test .= '.exe';
if (file_exists($test)) {
return $test;
}
$test = substr( $test, 0, -4 ) . '.cmd';
if (file_exists($test)) {
return $test;
}
$test = substr( $test, 0, -4 ) . '.bat';
if (file_exists($test)) {
return $test;
}
}

}

throw new pakeException('Can not find "'.$cmd.'" executable');
Expand Down