mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Allow Shell to be used on WinNT
This commit is contained in:
parent
f4d8908d80
commit
02cf435868
1 changed files with 38 additions and 5 deletions
|
@ -11,7 +11,22 @@ class Shell
|
||||||
$functions = array_map(function($x) {
|
$functions = array_map(function($x) {
|
||||||
return trim($x);
|
return trim($x);
|
||||||
}, explode(" ", ini_get("disable_functions")));
|
}, explode(" ", ini_get("disable_functions")));
|
||||||
return !in_array("system", $functions);
|
if(in_array("system", $functions))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if(Shell::isPowershell()) {
|
||||||
|
exec("WHERE powershell", $_x, $_c);
|
||||||
|
unset($_x);
|
||||||
|
|
||||||
|
return $_c === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function isPowershell(): bool
|
||||||
|
{
|
||||||
|
return strncasecmp(PHP_OS, 'WIN', 3) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function commandAvailable(string $name): bool
|
static function commandAvailable(string $name): bool
|
||||||
|
@ -19,6 +34,13 @@ class Shell
|
||||||
if(!Shell::shellAvailable())
|
if(!Shell::shellAvailable())
|
||||||
throw new Exceptions\ShellUnavailableException;
|
throw new Exceptions\ShellUnavailableException;
|
||||||
|
|
||||||
|
if(Shell::isPowershell()) {
|
||||||
|
exec("WHERE $name", $_x, $_c);
|
||||||
|
unset($_x);
|
||||||
|
|
||||||
|
return $_c === 0;
|
||||||
|
}
|
||||||
|
|
||||||
return !is_null(`command -v $name`);
|
return !is_null(`command -v $name`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,14 +63,25 @@ class Shell
|
||||||
function execute(?int &$result = nullptr): string
|
function execute(?int &$result = nullptr): string
|
||||||
{
|
{
|
||||||
$stdout = [];
|
$stdout = [];
|
||||||
|
|
||||||
|
if(Shell::isPowershell()) {
|
||||||
|
$cmd = escapeshellarg($this->command);
|
||||||
|
exec("powershell -Command $this->command", $stdout, $result);
|
||||||
|
} else {
|
||||||
exec($this->command, $stdout, $result);
|
exec($this->command, $stdout, $result);
|
||||||
|
}
|
||||||
|
|
||||||
return implode(PHP_EOL, $stdout);
|
return implode(PHP_EOL, $stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
function start(): string
|
function start(): string
|
||||||
{
|
{
|
||||||
|
if(Shell::isPowershell()) {
|
||||||
|
$cmd = escapeshellarg($this->command);
|
||||||
|
pclose(popen("start /b powershell -Command $this->command", "r"));
|
||||||
|
} else {
|
||||||
system("nohup " . $this->command . " > /dev/null 2>/dev/null &");
|
system("nohup " . $this->command . " > /dev/null 2>/dev/null &");
|
||||||
|
}
|
||||||
|
|
||||||
return $this->command;
|
return $this->command;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue