Added proc_open for execute commands in php
This commit is contained in:
parent
8ae64c74d2
commit
995208b3e1
1 changed files with 61 additions and 4 deletions
65
vendor/phangoapp/leviathanutils/src/Linux.php
vendored
65
vendor/phangoapp/leviathanutils/src/Linux.php
vendored
|
|
@ -7,7 +7,66 @@ class Linux {
|
||||||
|
|
||||||
static public function shell_command($arr_command, $exit_if_error=1) {
|
static public function shell_command($arr_command, $exit_if_error=1) {
|
||||||
|
|
||||||
$cmd=implode(' ', $arr_command);
|
$error=0;
|
||||||
|
|
||||||
|
for($x=1;$x<count($arr_command);$x++) {
|
||||||
|
|
||||||
|
$arr_command[$x]=escapeshellarg($arr_command[$x]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$descriptorspec = array(
|
||||||
|
0 => array("pipe", "r"), // stdin
|
||||||
|
1 => array("pipe", "w"), // stdout
|
||||||
|
2 => array("pipe", "w") // stderr
|
||||||
|
);
|
||||||
|
|
||||||
|
$pipes=[];
|
||||||
|
|
||||||
|
$process=proc_open($final_command, $descriptorspec, $pipes);
|
||||||
|
|
||||||
|
if(is_resource($process)) {
|
||||||
|
|
||||||
|
while($s=fgets($pipes[1])) {
|
||||||
|
|
||||||
|
echo $s;
|
||||||
|
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
while($e=fgets($pipes[2])) {
|
||||||
|
|
||||||
|
echo $e;
|
||||||
|
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($pipes[0]);
|
||||||
|
fclose($pipes[1]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
|
||||||
|
$result=proc_close($process);
|
||||||
|
|
||||||
|
if($result>0) {
|
||||||
|
|
||||||
|
echo 'Error executing command '.$cmd."\n";
|
||||||
|
|
||||||
|
if($exit_if_error) {
|
||||||
|
|
||||||
|
exit($result);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*$cmd=implode(' ', $arr_command);
|
||||||
|
|
||||||
$a = popen($cmd, 'r');
|
$a = popen($cmd, 'r');
|
||||||
|
|
||||||
|
|
@ -19,8 +78,6 @@ class Linux {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flush();
|
|
||||||
|
|
||||||
$result=pclose($a);
|
$result=pclose($a);
|
||||||
|
|
||||||
if($result>0) {
|
if($result>0) {
|
||||||
|
|
@ -38,7 +95,7 @@ class Linux {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue