PHPAtWork PHPAtWork - 6 months ago 52
Bash Question

output shell output from custom file via shell_exec in php

I would like to display the output of a shell script like it is shown in PuTTy or gnome-terminal via a php-script. I tried using shell_exec by invoking it:

$output = shell_exec('echo "return value: ";foo=$(nameOfFileToExecute); echo $foo');


In which way can I get the return string of the script which is stored on the webserver?

Answer

Try this instead:

    <?php 
         exec($your_shell_command_as_string, $arrayOfReturnedData);

        // NOW YOU CAN ACCESS ALL THE VALUES RETURNED BY THE SHELL COMMANDS VIA THE ARRAY.
        var_dump($arrayOfReturnedData); // DUMPS THE RESULTS OF THE SHELL COMMAND...

Hope this helps....