普通网友 2016-05-12 12:07
浏览 104
已采纳

通过php中的shell_exec从自定义文件输出shell输出

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?

  • 写回答

3条回答 默认 最新

  • douwen0647 2016-05-12 12:15
    关注

    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....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?