【问题标题】:xargs + curl "Failed writing body" (cannot save more than one result to file)xargs + curl “写入正文失败”(不能将多个结果保存到文件中)
【发布时间】:2020-03-05 23:01:23
【问题描述】:

我对 xargs 和 curl 有疑问。

我在“urls”文件中有 url 列表,我需要下载限制在前 9 行的这些内容并将所有内容保存到一个输出文件(或每个结果一个文件 - 没关系)。

xargs -P 4 -n 1 curl < urls | head -n 9 > outputfile

问题是,只有第一个结果是保存到文件,所有其他结果都给出错误“(23)写入正文失败”。即使我没有将结果保存到文件中,控制台中也会出现“(23) Failed writing body”错误。

总之: 我需要从文件中下载前 9 行 XXXX URL,并将其保存到一个输出文件,或者每个 URL 一个文件。

Cygwin (Windows 10) 和 MacOs 上存在问题。

【问题讨论】:

    标签: linux bash curl pipe xargs


    【解决方案1】:

    您的管道将输出限制为 xargs 输出的前 9 行。试试这个吧。

    xargs -P 4 -i sh -c 'curl {} | head -n 9' <urls >outputfile
    

    这可能会无法控制地混淆并行提取的输出行。如果你想避免这种情况,也许看看 GNU parallel。如果这是不可接受的,则可以将每个文件写入一个单独的临时文件,并在提取完成后连接并删除临时文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-17
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多