diff --git a/cmpUtil.php b/cmpUtil.php index f859c33..77be9bd 100644 --- a/cmpUtil.php +++ b/cmpUtil.php @@ -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]);