在远程 apache 上(首先 PHP Version 5.3.29
| 最终更新到 7.04,没有启用安全模式),我尝试运行一个微小的 20 个字符的 c 文件“ccc”
exec(), popen(), shell_exec(), system(), passthru(), backtick
...其中 6 种方法中有 5 种在本地取得了成功,到目前为止 6 种方法中有 0 种在远程取得了成功。
我在 6 种情况中的 3 种中得到返回值“1”( passthru, exec, system
),并且使用 popen
得到一个空(?)流(如果可能的话) (见下文)。
exec(), passthru(), system()
愿意在远程服务器上运行像 ls 这样的命令,但是用 ccc 不给我任何东西,c-testfile 只包含 printf("c did");
) 在里面。
升级到php-Version 7.04
后服务器已配置(php-ini)没有安全模式。
我的文件 exec.php 仅尝试以 6 种方式运行 ccc(下面简称)
// start source
error_reporting(E_ALL);
echo exec ('ls', $out0, $error0);
$popen = popen ($cpath.'ccc', 'r');
stream_get_contents ( $popen );
shell_exec ($cpath.'ccc');
passthru ($cpath.'ccc', $error3);
exec ($cpath.'ccc', $out4, $error4);
system ($cpath.'ccc', $error5);
$output = `$cpath.ccc`;
echo '20160316 errors 0-6 | 0: '.$error0.' | 3: '.$error3.' | 4: '.$error4.' | 5: '.$error5.'<br/>';
echo '20160316 outputs 0-6 | 0: '.gettype($out0).' | 1: '.get_resource_type($popen).' | 4: '.gettype($out4).';
// end source
该文件确实在本地服务器上打开了 c 文件,没有错误, 但没有输出,并且在远程服务器上返回 1。
最佳答案
听起来 C 程序只是本地的。该程序必须位于远程服务器上。另外,apache 服务必须具有读取和执行权限。
关于php - 远程服务器上的 exec() 仅返回 return-var 1 |尝试了7种方法但没有成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36038272/