Output of shell_exec gets truncated to 100 characters

好久不见. 提交于 2019-12-10 17:56:09

问题


When run in shell the following command,

curl -F file=@filename http://192.168.0.1

produces the following output:

Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)
verdict = success!

When I run it in php, either by using shell_exec(), exec() or the backtick operator,

$verdict = `curl -F file=@$filename $url`;

I get the following output:

Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (class

The output gets truncated at exactly 100 characters. I cannot for the life of me figure out why this is. Why is this, and how do I get the full output in a php variable?


回答1:


You may avoid executing the cURL operation via terminal because

  • It is very likely that not every server will support executing the commands via code.
  • It is very likely that the safe-mode is enabled in production.
  • Not every user that executes the above command in terminal will have permission to execute.
  • Not every user that executes the above command without specifying the full path of the command (like /usr/bin/curl)

Consider using PHP's built-in cURL option to implement this via

CURLOPT_POSTFIELDS


来源:https://stackoverflow.com/questions/17052760/output-of-shell-exec-gets-truncated-to-100-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!