bash php 运行 shell 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8420290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:09:17  来源:igfitidea点击:

php run shell script

phpbash

提问by Kamran224

I'm trying to run a shell script from a php frontend

我正在尝试从 php 前端运行 shell 脚本

heres the shell file (run.sh chmod to 777)

这是 shell 文件(run.sh chmod 到 777)

#!/bin/bash
wget -O index.html http://markets.usatoday.com/custom/usatoday-com/html-mktscreener.asp
python hw7-9.py index.html 
echo "done";

Heres the php front end

这是php前端

<?php
   $output = shell_exec("run.sh");
   echo "<pre>$output</pre>";
?>

But it php page doesn't return anything except

但它的 php 页面除了

<pre></pre>

回答by Mike

Have you tried doing error_reporting(-1);at the top of your PHP script. Likely shell_execis disabled on your server.

你有没有试过error_reporting(-1);在你的 PHP 脚本的顶部做。shell_exec您的服务器上可能已禁用。

回答by Nitesh

Would you try $output = shell_exec("sh run.sh");

你会试试 $output = shell_exec("sh run.sh");

回答by dgc

Check what user the php/web server is actually run as - e.g. "www-user" may have no permissions whatsoever to do the things your script is trying to do (and for good reason).

检查 php/web 服务器实际运行的用户身份 - 例如,“www-user”可能没有任何权限来执行您的脚本尝试执行的操作(并且有充分的理由)。