modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-13 17:32:44 +04:00
parent a09f3a0a2b
commit 5c4a2e83ad
3 changed files with 6 additions and 19 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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 = [];