开发者

Why isn't this shell command giving the desired result?

I am using the wkhtmtoimage library on my server, and I have managed to get the output for the following command when I am 开发者_JAVA技巧running in PuTTY:

wkhtmltoimage www.google.com test.jpg

But, when I use the following shell command I don't get the output, and I don't know why.

$filnename = "test.jpg";
$url = "http://www.google.com";    
shell_exec("wkhtmltoimage $url $filename");

Even I tried with this variation instead, but still without getting the desired result:

shell_exec("/usr/local/bin/wkhtmltoimage $url $filename");

What am I doing wrong?

Edit:

I downloaded the Linux binary and put it into the folder then I ran it.Whether I need to restart the server the changes affected?

shell_exec command is allowed because we used it for ffmpeg(already installed one)


I cannot give an exact solution but if you can try out what I write I might be of help. I will list more solutions if the one I am providing does not work.

Solution proposal 1:
Use quotes around url and filename

shell_exec("wkhtmltoimage \"$url\" \"$filename\"");

Solution proposal 2:
Try redirecting streams to files and type the contents.

shell_exec("wkhtmltoimage \"$url\" \"$filename\" > output.txt 2> error.txt");


May be user under which PHP (or Apache) runs have no permissions to run this tool. Try printing output of this command or just use passthru() to directly print output of command. Another solution is to pass output to files as @Cem_Kalyoncu wrote.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜