作为一个单独的工具,它工作得很好:

curl "someURL"
curl -o - "someURL"

但这在流水线上行不通:

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

它返回:

(23) Failed writing body

管道cURL输出的问题是什么?如何缓冲整个cURL输出,然后处理它?


当前回答

我犯了同样的错误,但原因不同。在我的情况下,我有(tmpfs)分区只有1GB空间,我正在下载大文件,最终填满了该分区上的所有内存,我得到了和你一样的错误。

其他回答

对于完整性和将来的搜索:

这取决于cURL如何管理缓冲区,缓冲区使用-N选项禁用输出流。

例子: curl -s -N "URL" | grep -q欢迎

我添加了flag -s,它完成了任务。例如:curl -o- s https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

所以这是编码的问题。Iconv解决了这个问题

curl 'http://www.multitran.ru/c/m.exe?CL=1&s=hello&l1=1' | iconv -f windows-1251 | tr -dc '[:print:]' | ...

用sudo尝试命令对我有用。例如:

sudo curl -O -k 'https url here'

注意:-O(这是大写o,不是零)& -k https url。

如果你正在尝试类似source <(curl -sS $url)这样的东西,并得到(23)Failed writing body错误,这是因为在bash 3.2 (macOS的默认)中,源进程替换不起作用。

相反,您可以使用这个解决方案。

source /dev/stdin <<<"$( curl -sS $url )"