gpt4 book ai didi

PHP - Shell_exec 和 exec 在运行时返回 false

转载 作者:行者123 更新时间:2023-12-04 19:15:07 30 4
gpt4 key购买 nike

我已经对这个主题进行了一些广泛的研究。但我什么也没找到。似乎当我运行 shell_exec() 时它总是返回 false。即使输出为真。

PHP 脚本:

$tmp1 = exec("/var/www/html/online/files/test.sh 2>&1");

test.sh Bash 脚本:
var=$(screen -ls | awk -F'[. ]' '/.onoff/ {print $1}')
if [ -z "$var" ]; then
echo "false"
else
echo "true"
fi

它正在测试一个名为“onoff”的屏幕的屏幕 PID,该屏幕在运行时正在运行,但仍返回 false。即使我在 PuTTY 中使用该命令,它也会返回 true。

以下是文件的权限:
root@s94029:~# ls -la /var/www/html/online
drwxr-xr-x 3 root root 4096 Dec 18 12:34 .
drwxr-xr-x 12 root root 4096 Dec 18 09:30 ..
drwxr-xr-x 2 root root 4096 Dec 18 11:54 files
-rwxr-xr-x 1 root root 221 Dec 18 04:59 index.css
-rwxr-xr-x 1 root root 4310 Dec 18 12:55 index.php
-rwxr-xr-x 1 root root 417 Dec 18 06:40 servers.php
root@s94029:~# ls -la /var/www/html/online/files
drwxr-xr-x 2 root root 4096 Dec 18 11:54 .
drwxr-xr-x 3 root root 4096 Dec 18 12:34 ..
-rwxr-xr-x 1 root root 115 Dec 18 11:54 test1.sh
-rwxr-xr-x 1 root root 114 Dec 18 11:54 test.sh

你能帮忙的话,我会很高兴!

谢谢!

最佳答案

试试exec($command, $output, $status)检查输出和状态变量。状态变量中的非零是错误。零是成功。

完成此检查后,文件的所有权...如果您仍然遇到问题,请将 www-data (apache) 用户添加到文件的所有权中。

exec('/var/www/html/online/files/test.sh 2>&1', $output, $status);

print_r($output);
echo $status;

关于PHP - Shell_exec 和 exec 在运行时返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41212053/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com