From fe177b2a5de903ebca1c70f9c09e7da944d9ea09 Mon Sep 17 00:00:00 2001 From: lganee <ludovic.ganee@libriciel.coop> Date: Thu, 14 Nov 2024 15:46:11 +0100 Subject: [PATCH] backport de la fonction Exec::proc --- src/Utility/Exec.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Utility/Exec.php b/src/Utility/Exec.php index aeb47788d..cfe17b30d 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"); + } + } } -- GitLab