Add cmpShellEsc

This commit is contained in:
cmp167
2023-08-23 21:00:54 +12:00
parent b08e3df595
commit 8301ee83d3

View File

@@ -249,8 +249,7 @@
return $a;
}
function cmpShellEscArr($cmaRaw) {
function cmpShellEscStr($str) {
$ttr = array(
"\t" => "\\\t", "\$" => "\\\$",
"\\" => "\\\\", "\"" => "\\\"",
@@ -265,24 +264,29 @@
"?" => "\\?" , "!" => "\\!"
);
if(@$str[0] == "asis")
return @$str[1];
return strtr($str, $ttr);
}
function cmpShellEscArr($cmaRaw) {
$cmaEsc = array();
for($i = 0; $i < count($cmaRaw); $i++) {
if(@$cmaRaw[$i][0] == "asis") {
$cmaEsc[] = $cmaRaw[$i][1];
continue;
}
$cmaEsc[] = strtr($cmaRaw[$i], $ttr);
$cmaEsc[] = $this->cmpShellEscStr($cmaRaw[$i]);
}
return $cmaEsc;
}
function cmpShellEscStr($cmaRaw) {
$cmaEsc = $this->cmpShellEscArr($cmaRaw);
function cmpShellEsc($cmaRaw) {
if(is_array($cmaRaw)) {
$cmaEsc = $this->cmpShellEscArr($cmaRaw);
return join(" ", $cmaEsc);
}
return join(" ", $cmaEsc);
return $this->cmpShellEscStr($cmaRaw);
}
function cmpSysExec($cmaRaw, $opt = []) {
@@ -333,8 +337,23 @@
fclose($ppsAll[0]);
}
$out = stream_get_contents($ppsAll[1], 1048576);
$err = stream_get_contents($ppsAll[2], 1048576);
if(@$opt["stdOutRead"]) {
$this->d("Read loop");
while(!feof($ppsAll[1])) {
$out = stream_get_contents($ppsAll[1], 1048576);
// $err = stream_get_contents($ppsAll[2], 1048576);
($opt["stdOutRead" ]["call"]) (
$out,
$opt["stdOutRead"]
);
}
}
else {
$out = stream_get_contents($ppsAll[1], 1048576);
$err = stream_get_contents($ppsAll[2], 1048576);
}
fclose($ppsAll[1]);
fclose($ppsAll[2]);