php - 无法使用 PHP 运行 shell 脚本文件

标签 php linux shell sh

您好,我无法使用我的 php 代码运行 .sh 文件。

 Files:  index.php and .sh files are in the same directory.

我尝试过的:

 echo shell_exec('sh shell_file.sh'); //Did not execute
 echo shell_exec('shell_file.sh'); //Did not execute
 echo exec('shell_file.sh'); //Did not execute

但是当我手动运行 shell_file.sh 文件时,它确实会执行。

最佳答案

尝试这样:

您需要做的是用程序调用该文件。按照评论中的建议使用 bash 或 sh 调用它:

echo shell_exec('sh /shell_file.sh');

另一个选择可能是:

$contents = file_get_contents('/shell_file.sh');
echo shell_exec($contents);

我认为第一个选择会更好。

关于php - 无法使用 PHP 运行 shell 脚本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30507840/

相关文章:

php - 在 PHP 中记录的上传缩略图

PHP PDO 准备插入 - 不插入数据且不显示错误

linux - 使用linux路由器修改H323 tcp数据包

linux - sed 字符串反转

linux - 如何在 Red Hat Linux Server 中查找 RAM 大小?

shell - 如何将输入字符串替换为文件?

bash - 如果节尚不存在,如何向节添加行

php - 如何检查当前日期/时间是否超过设定的日期/时间?

javascript - 在ajax中接收php多维数组

linux - 使 linux SPLIT 命令与 Mac OS 终端兼容