Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

PHP Execute BASH: echo $output LIVE

General discussions related to php

Moderators: macek, egami, gesf

PHP Execute BASH: echo $output LIVE

Postby tmaiden » Fri Feb 21, 2014 6:25 pm

I'm having the worst trouble trying to understand why I cannot print out BASH commands as they happen.

Here is my code:
/home/owner/scripts/helper.sh
Code: Select all
# helper.sh
echo "" > /home/owner/scripts/new.txt
ping -c 4 google.com >> /home/owner/scripts/new.txt
echo "FINISHED" >> /home/owner/scripts/new.txt


http://localhost/test.php
Code: Select all
<?php
        echo "Pre shell_exec<br/>";
        shell_exec("sh /home/owner/scripts/helper.sh > /dev/null 2>/dev/null &");
        echo "Post shell_exec<br/>";

        echo "start while<br/>";
        while ($output !== "FINISHED" . chr(10) . "") {
//              ob_implicit_flush(true);
                $output = shell_exec("tail -1 /home/owner/scripts/new.txt");
                echo "". $output . "<br/>";
        }
        echo "end while<br/>";

        echo "<pre>End of PHP Script</pre>";
?>


Any help would be greatly appreciated!
tmaiden
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Jun 15, 2012 5:58 am

Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.