douzhang8840
2014-11-02 06:43
浏览 166
已采纳

Mac OSX cmd从命令行工作,从php shell_exec()失败

I am on Mac OS X 10.9.4

I can run this command successfully from the command line to produce an image or google.com

wkhtmltoimage http://www.google.com /Users/me/Sites/google.jpg

But when I tried to execute the same command from inside my website using the php command

$cmd='wkhtmltoimage http://www.google.com /Users/me/Sites/google.jpg';
shell_exec($cmd);

I get the following error:

sh: wkhtmltoimage: command not found

Is this a permission issue? If so how can I get it to work?

====

Update

I set the full path like @Mureinik suggested and I made some progress now the error message I get is

Loading page (1/2)
[>                                                           ] 0%
[======>                                                     ] 10%
[=============>                                              ] 23%
[==================>                                         ] 31%
[===================>                                        ] 33%
[========================>                                   ] 41%
[=====================================>                      ] 62%
[=======================================>                    ] 65%
[========================================>                   ] 67%
[=========================================>                  ] 69%
[==========================================>                 ] 71%
[==============================================>             ] 78%
[==================================================>         ] 84%
[===================================================>        ] 86%
[============================================================] 100%
Rendering (2/2)                                                    
[>                                                           ] 0%
[===============>                                            ] 25%
Error: Could not write to output file                             
Error: Could not save image
[============================================================] 100%
Done                                                               
Exit with code 1, due to unknown error.

Am I having a permission issue now?

====

Update

I changed the file permission to my destination and that took care of it.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutuoji8418 2014-11-02 06:52
    已采纳

    The issue is probably that shell_exec uses a different $PATH then you, and thus can't locate wkhtmltoimage. From you own shell, you can use which wkhtmltoimage to determine where exactly it's installed, and then use shell_exec with the full path, e.g.:

    $cmd='/opt/wkhtmltoimage http://www.google.com /Users/me/Sites/google.jpg';
    shell_exec($cmd);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douzoudang1511 2017-10-22 16:47

    For anyone else who stumbles across this answer, my command involved saving an image into a directory and shell_exec didn't have write permissions for that directory. Me as a user did have rights which is why I was able to execute the query manually successfully.

    So I just changed the permissions of the directory so that it could be written to.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题