diff --git a/src/Utility/Exec.php b/src/Utility/Exec.php index aeb47788dc7b43fe0c9c9a4aa3398a158a62d0bf..cfe17b30d5dd0cd1ec3a418aae5205983bd08648 100644 --- a/src/Utility/Exec.php +++ b/src/Utility/Exec.php @@ -5,6 +5,7 @@ namespace AsalaeCore\Utility; +use AsalaeCore\Exception\GenericException; use AsalaeCore\Utility\Object\CommandResult; use Cake\Core\Configure; use Cake\I18n\FrozenTime; @@ -300,4 +301,26 @@ class Exec file_put_contents(LOGS . 'exec.log', $msg, FILE_APPEND); } } + + /** + * Proc_open avec redirection sur les sorties du terminal (par défaut) + * @param string $command + * @param array|null $descriptor_spec + * @return int + */ + public function proc(string $command, ?array $descriptor_spec = null): int + { + $descriptor_spec = $descriptor_spec ?? [ + ['file', 'php://stdout', 'w'], + ['file', 'php://stderr', 'w'], + ]; + + $process = proc_open($command, $descriptor_spec, $pipes); + + if (is_resource($process)) { + return proc_close($process); + } else { + throw new GenericException("unable to launch command"); + } + } }