dongyuli0964 2013-01-31 18:01
浏览 107
已采纳

php exec()函数不适用于ubuntu + nginx + fpm上的所有命令

I can see the result of:

echo exec("whoami"); // will output "www-data"

however if I try to run a real world command:

echo exec("casperjs myscript.js /foo/bar");

then nothing happens:

  • no output (the casperjs script should output some stdout log messages)
  • no action (the script should create an image, using an absolute path, but it doesn't)
  • no errors from PHP
  • no output of the shell command

I've searched on StackOverflow, and went to try alternative ways (tested first in the shell, to be sure they work):

echo exec("casperjs /absolute/path/to/myscript.js");
echo exec("/usr/local/bin/casperjs /absolute/path/to/myscript.js");

I tested also other combinations, using system(), shell_exec() and even passthru() but it's always the same thing: no error, no output, even in php log files, so it is very, very hard to understand the problem :(

  • 写回答

1条回答 默认 最新

  • doureng1083 2013-01-31 18:05
    关注

    Try echo exec("casperjs myscript.js /foo/bar 2>&1"); to redirect stderr to stdout which wouldn't otherwise show.

    It could be an error in your cmdline or maybe casperjs is not in your $PATH, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?