dtvgo28624 2013-09-03 11:11
浏览 459

为什么shell_exec不执行文件但执行简单命令?

Is there any reason why I can not complied files in PHP's shell_exec/exec/system function?

Example of something that does work in command line and PHP's shell_exec function:

<?php
$data = shell_exec("ls");
echo $data;
?>

Example of something that does not work in PHP's shell_exec function but will work in command line (I can confirm that):

<?php
$data = shell_exec("./c-compiled-file argv1 argv2 argv3");
echo $data;
?>

Is there anything I can do on my server so this will work? I've looked everywhere and no solutions I found fixed the problem. The compiled file is in the same directory as the PHP script as well, it just won't execute it. Also if you're asking, yes I have tried this with SSH2 and it still will not execute.

Also PHP is not in safe mode and NO functions are disabled.

  • 写回答

3条回答 默认 最新

  • duanfan1965 2013-09-03 11:16
    关注

    You want to use system in the second case, and not shell_exec.

    system executes an external program and displays the output.

    shell_exec executes a command via shell and returns the complete output as a string.

    and for good measure:

    exec simply executes an external program.

    Furthermore you want to make sure your external program is executable and (though you have stated it, I'll restate this) has execute permissions for the user which is running the web server. You also want to make sure the directory your external program is running in has the ability to write to its directory or /tmp or whatever output directory you have set.

    Finally you should always use absolute paths for executing things like this in cron or php or whatever... so don't use ./c-compiled-file argv1 argv2 argv3, but instead use /home/username/c-compiled-file argv1 argv2 argv3 or whatever the full path is.

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献