shell_exec returns empty string

纵饮孤独 提交于 2019-12-01 21:16:25

I changed the sudoers to ALL ALL = (ALL) :NOPASSWD ALL (very un-secure, but just to find something sure to work),

then I did a

sudo -u myusername /path/to/script.sh

where script.sh has export VAR=value export VAR=value

for all the environmental variables that are necessary (you can do a printenv from a user who can properly pacmd to see what you need. probably a good HOME and maybe an XAUTHORITY).

hope that helps

Most of the time php scripts are run by Apache, if thats the case with your script then Apache user may not have enough permissions to run this command. Check that first. If its run as CLI script then check if PHP user can run the script.

Maybe this is why that

Try to use system

You may want to try " > file.txt 2>&1" at the end of your command. It will redirect the outputs to a separate file.

$command = "cmd command > outputs.txt 2>&1";
shell_execute($command);

You'll end up with a file that looks something like this:

b'cmd command output contents\r\n'
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!