Link to home
Start Free TrialLog in
Avatar of limneos
limneos

asked on

shell output problem

Hello.

I'm trying to run a command using e.g. system('ls -l') and have the output printed while it's being processed , not gathered in total when it's finished.

I tried:

ob_start();
system('ping -c4 www.someip.com');
$output = ob_get_contents();
ob_end_clean();
print "<pre>";
echo $output;
print "</pre>";


The above example works, but it prints the result when it's finished,
which means that if I want to execute a long script and watch the progress on the the web page,
I will have to wait for the process to finish and then view it in total.

Is there a way to view the progress second by second, or in real time, printed on the web page?

Thank you in advance for your help.
ASKER CERTIFIED SOLUTION
Avatar of snoyes_jw
snoyes_jw
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Tomeeboy
Tomeeboy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of limneos
limneos

ASKER

Well, thank you but none of the above work as expected.

The example of TeRReF simply prints out the same thing 10 times.

In order to be more specific and help you all understand what I'm trying to achieve, I'll give you a particular example that most of us have seen.

When we use Cpanel(TM) , and let's say, we do an apache update, it takes us to a page where we can see the progress of the update, just like it's printed on shell.It is not fake, it gets values right from the shell.

It reads the lines from shell either in real time, or by making the php script to "wait" for a while until the results are updated...

Something like this...Thank you all for your assistance
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of limneos

ASKER

could we possible ask from the process to run on the background and echo its output to a file and read the file continuously?
Avatar of limneos

ASKER

and one more hint I need:
Is there any way to display the error messages that exec or system returns?
e.g. system('aiuluad -ls);

-bash: aiuluad: command not found

so we can see what the error was?
Avatar of limneos

ASKER

Well....the last problem I had, I solved it from the manual ;)

$command="ls /root";
system( $command . " &> /tmp/error " );
$filename = "/tmp/error";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
print "<pre>$contents</pre>";

Prints  : ls: /root: Permission denied

Still looking for a solution of the first problem....

Thank you all