From 5c4a2e83ad3a1f31b8a4111d919cc94c4bf1a7d2 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 13 Jun 2024 17:32:44 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- src/os/proc/AbstractCmd.php | 17 ++--------------- src/os/proc/AbstractCmdList.php | 6 +++--- src/os/proc/CmdPipe.php | 2 +- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/os/proc/AbstractCmd.php b/src/os/proc/AbstractCmd.php index d11f7b1..0560634 100644 --- a/src/os/proc/AbstractCmd.php +++ b/src/os/proc/AbstractCmd.php @@ -175,7 +175,7 @@ abstract class AbstractCmd implements ICmd { } } - abstract function getCmd(?string $sep=null): string; + abstract function getCmd(?string $sep=null, bool $exec=false): string; function passthru(int &$retcode=null): bool { passthru($this->getCmd(), $retcode); @@ -193,21 +193,8 @@ abstract class AbstractCmd implements ICmd { return $retcode == 0; } - /** - * retourner true s'il faut utiliser `exec` avec {@link fork_exec()} - * - * ne pas utiliser `exec` si des variables sont définies ou si c'est une - * composition de plusieurs commandes - */ - protected function useExec(): bool { - return $this->sources === null - && $this->vars === null - && count($this->cmds) == 1; - } - function fork_exec(int &$retcode=null): bool { - $cmd = $this->getCmd(); - if ($this->useExec()) $cmd = "exec $cmd"; + $cmd = $this->getCmd(null, true); sh::_fork_exec($cmd, $retcode); return $retcode == 0; } diff --git a/src/os/proc/AbstractCmdList.php b/src/os/proc/AbstractCmdList.php index cf5f7f2..68b84a2 100644 --- a/src/os/proc/AbstractCmdList.php +++ b/src/os/proc/AbstractCmdList.php @@ -31,7 +31,7 @@ abstract class AbstractCmdList extends AbstractCmd { return $this; } - function getCmd(?string $sep=null): string { + function getCmd(?string $sep=null, bool $exec=false): string { if ($sep === null) $sep = "\n"; $actualCmd = []; @@ -45,8 +45,8 @@ abstract class AbstractCmdList extends AbstractCmd { } $parts[] = $cmd; } - $psep = $this->sep ?? $sep; - $actualCmd[] = implode($psep, $parts); + if (count($parts) == 1 && $exec) $parts[0] = "exec $parts[0]"; + $actualCmd[] = implode($this->sep ?? $sep, $parts); return implode($sep, $actualCmd); } diff --git a/src/os/proc/CmdPipe.php b/src/os/proc/CmdPipe.php index 9d911e5..baec3a3 100644 --- a/src/os/proc/CmdPipe.php +++ b/src/os/proc/CmdPipe.php @@ -49,7 +49,7 @@ class CmdPipe extends AbstractCmd { return $this; } - function getCmd(?string $sep=null): string { + function getCmd(?string $sep=null, bool $exec=false): string { if ($sep === null) $sep = "\n"; $actualCmd = [];