我想通过 php 运行 php ../cat1/index.php gr_s2/3/gr-n40 1200
命令。
结果 shell_exec 返回 NULL,但是当我在 cmd 上尝试该命令时,输出显示正确。
在 php 和 shell_exec 中发生了什么?!
注意:具有不同参数的命令(如:php ../cat1/index.php gr_s2/3/gr-n40 800
)在两者(php 和 cmd)中都可以正常工作。
最佳答案
在 shell_execute 的 php 手册页中有一个注释:
Note: This function can return NULL both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. exec() should be used when access to the program exit code is required.
来源:http://php.net/manual/en/function.shell-exec.php
所以你的代码运行出错。尝试使用 exec。 如果需要,请插入要检查的代码(或 block )。
关于php shell_exec 返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34628827/