I have a PHP script which prints the output of a bash script (actually it is an expect script), which looks like this:
<?php
ob_implicit_flush(true);
ob_end_flush();
$cmd = "./expect_script.sh";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo '<pre>';
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print $s;
}
}
echo '</pre>';
?>
So I wanted to get the real time output with automatic scroll at the end of the page with every new line appearance and I found this: printing process output in realtime
Then I added the proposed html code to my script as follows:
<html><head>
<script language="javascript">
var int = self.setInterval("window.scrollBy(0,1000);", 200);
</script>
</head>
<body>
<?php
ob_implicit_flush(true);
ob_end_flush();
$cmd = "./expect_script.sh";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo '<pre>';
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print $s;
}
}
echo '</pre>';
?>
</body>
</html>
However, when script finishes the web browser won't let me browse to the top of the page because it is still scrolling to the bottom.
How shall avoid it so that I can browse once the script is finished?