From 995208b3e1f17e6e3ba81c448f20d37cdd7bb5f6 Mon Sep 17 00:00:00 2001 From: absurdo Date: Mon, 27 Nov 2023 13:05:13 +0100 Subject: [PATCH] Added proc_open for execute commands in php --- vendor/phangoapp/leviathanutils/src/Linux.php | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/vendor/phangoapp/leviathanutils/src/Linux.php b/vendor/phangoapp/leviathanutils/src/Linux.php index aa585a0..2c41e39 100644 --- a/vendor/phangoapp/leviathanutils/src/Linux.php +++ b/vendor/phangoapp/leviathanutils/src/Linux.php @@ -7,7 +7,66 @@ class Linux { static public function shell_command($arr_command, $exit_if_error=1) { - $cmd=implode(' ', $arr_command); + $error=0; + + for($x=1;$x 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'); @@ -19,8 +78,6 @@ class Linux { } - flush(); - $result=pclose($a); if($result>0) { @@ -38,7 +95,7 @@ class Linux { } - } + }*/ }