2013-01-31 18:01
浏览 102

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 :(

图片转代码服务由CSDN问答提供 功能建议


  echo exec(  “我是谁”);  //将输出“www-data”


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


  • 没有输出(casperjs脚本应该输出一些stdout日志消息)
  • 没有动作(脚本应该创建一个图像,使用绝对路径,但它没有)
  • 没有来自PHP的错误
  • 没有输出shell命令

    我在StackOverflow上搜索过,然后去了 尝试替代方法(首先在shell中测试,以确保它们有效):

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

    我测试了其他组合,使用 system() shell_exec()甚至 passthru() 但它总是一样的:没有错误,没有输出,即使在php中也是如此 日志文件,所以很难理解这个问题:(

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题