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 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败