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 { } - } + }*/ }