无法使用 PHP 运行 shell 脚本文件 [英] Unable to run shell script file using PHP

查看:81
本文介绍了无法使用 PHP 运行 shell 脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用我的 php 代码运行 .sh 文件.

Hi I am unable to run the .sh file using my php code.

 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 文件时,它确实会执行.

But when I run the shell_file.sh file manually it does execute.

推荐答案

试试这个:

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

What you need to do is call the file with a program. Call it with bash or sh as suggested in the comment:

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

另一种选择可能是:

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

不过我认为第一个选项会更好.

I think the first option would be better however.

这篇关于无法使用 PHP 运行 shell 脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆