shell_exec的输出被截断为100个字符 [英] Output of shell_exec gets truncated to 100 characters

查看:200
本文介绍了shell_exec的输出被截断为100个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在shell中运行以下命令时,

When run in shell the following command,

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

产生以下输出:

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

在php中运行时,可以使用 shell_exec() exec()或反引号运算符,

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

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

我得到以下输出:

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

输出被截断为正好100个字符。我一生都无法弄清楚为什么这是为什么,如何在php变量中获取完整的输出?

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?

推荐答案

您可以避免执行通过终端进行cURL操作,因为

You may avoid executing the cURL operation via terminal because


  • 很有可能不是每个服务器都支持通过代码执行命令。

  • 很有可能在生产中启用了安全模式。

  • 并非每个在终端中执行上述命令的用户都有权执行。

  • 并非每个执行上述命令而不指定命令完整路径的用户(例如/ usr / bin / curl)

  • 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)

考虑使用PHP的内置功能 cURL 选项可通过以下方式实现

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

CURLOPT_POSTFIELDS

这篇关于shell_exec的输出被截断为100个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆