您好,我无法使用我的 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/