private function suExec($command, $verbose = null)
{
if (!($proc = proc_open($command, [STDIN, ["pipe", "w"], ["pipe", "w"]], $pipes))) {
$this->status = -1;
throw new Exception("Failed to run {$command}");
}
$stdout = $pipes[1];
$passwd = 0;
$checks = 10;
while (!feof($stdout)) {
$R = [$stdout];
$W = [];
$E = [];
if (!stream_select($R, $W, $E, null)) {
continue;
}
$data = fread($stdout, 0x1000);
/* only check a few times */
if ($passwd < $checks) {
$passwd++;
if (stristr($data, "password")) {
$passwd = $checks + 1;
printf("\n%s", $data);
continue;
}
} elseif ($passwd > $checks) {
/* new line after pw entry */
printf("\n");
$passwd = $checks;
}
if ($verbose === null) {
print $this->progress($data, 0);
} else {
if ($verbose) {
printf("%s", $data);
}
$this->output .= $data;
}
}
if ($verbose === null) {
$this->progress("", PHP_OUTPUT_HANDLER_FINAL);
}
return $this->status = proc_close($proc);
}