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

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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码