我已经尝试了很多次flush()
使脚本同步工作,脚本只打印第一个命令“gcloud compute ssh yellow”和“ls -la”的数据,我希望让脚本在每次执行时打印输出fputs()
。
<?php
$descr = array( 0 => array('pipe','r',),1 => array('pipe','w',),2 => array('pipe','w',),);
$pipes = array();
$process = proc_open("gcloud compute ssh yellow", $descr, $pipes);
if (is_resource($process)) {
sleep(2);
$commands = ["ls -la", "cd /home", "ls", "sudo ifconfig", "ls -l"];
foreach ($commands as $command) {
fputs($pipes[0], $command . " \n");
while ($f = fgets($pipes[1])) {
echo $f;
}
}
fclose($pipes[0]);
fclose($pipes[1]);
while ($f = fgets($pipes[2])) {
echo "\n\n## ==>> ";
echo $f;
}
fclose($pipes[2]);
proc_close($process);
}
提前致谢