为什么CURL返回值和错误(23)失败写身体? [英] Why CURL return and error (23) Failed writing body?

查看:9270
本文介绍了为什么CURL返回值和错误(23)失败写身体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它的工作原理确定为一个单一的工具:

It works ok as a single tool:

curl "someURL"
curl -o - "someURL"

,但它不能在一个流水线工作:

but it doesn't work in a pipeline:

curl "someURL" | tr -d '\n'
curl -o - "someURL" | tr -d '\n'

返回的是:

(23) Failed writing body

这是在管道的问题卷曲输出?如何缓冲整个卷曲输出,然后处理呢?

What is the problem in the piping the curl output? How to buffer the whole curl output and then handle it?

推荐答案

这发生在一个管道程序(如grep)来关闭previous程序之前读管道写完整个页面。

This happens when a piped program (e.g. grep) closes the read pipe before the previous program is finished writing the whole page.

卷曲URL| grep的-qs富,只要有grep的它想它会从卷曲关闭读取流。卷曲不指望这一点,并发出了失败的身体写作的错误。

In curl "url" | grep -qs foo, as soon as grep has what it wants it will close the read stream from curl. cURL doesn't expect this and emits the "Failed writing body" error.

一个解决方法是将管道通过中介程序,将其送入下一个程序之前,请务必阅读整个页面流。

A workaround is to pipe the stream through an intermediary program that always reads the whole page before feeding it to the next program.

例如

curl "url" | tac | tac | grep -qs foo

TAC 是一个简单的Unix程序,读取整个输入页面和反转线序(因此我们运行了两次)。由于它具有读取整个输入查找的最后一行,也不会输出任何东西到grep,直到卷曲完成。 grep的仍将关闭读取流时,它有什么它寻找,但它只会影响交,不发出错误。

tac is a simple Unix program that reads the entire input page and reverses the line order (hence we run it twice). Because it has to read the whole input to find the last line, it will not output anything to grep until cURL is finished. Grep will still close the read stream when it has what it's looking for, but it will only affect tac, which doesn't emit an error.

这篇关于为什么CURL返回值和错误(23)失败写身体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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