问题
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