curl 输出未重定向到文件

问题描述 投票:0回答:1

我正在尝试将curl 的输出重定向到文件。 根据curl的手册页,我必须附加:

--output <file.txt> 

但是,即使我这样做,输出也不会被重定向。 有人可以指导一下,我做错了什么吗?我正在尝试执行以下请求:

$ curl -v -H "Content-Type: application/json" -d '{"json":"data"}' --user [email protected]:password http://host.com/inventory/ --output haha.txt

我在终端/shell 上获取输出,但它只是无法到达文件。

http curl post get libcurl
1个回答
0
投票

--output
(或
-o
)将下载的内容写入给定文件(而不是将其写入标准输出)。 cURL 的其余输出(进度表、错误消息、详细模式等)仍然写入 stderr,并显示在终端中。 https://en.wikipedia.org/wiki/Standard_streams

您可以使用 cURL 的

--stderr
选项将该输出重定向到文件或 shell 的 重定向运算符

来自手册页:

  --stderr
         Redirect all writes to stderr to the specified file instead. If the file
         name is a plain '-', it is instead written to stdout.

         If this option is used several times, the last one will be used.

         See also -v, --verbose and -s, --silent.

使用 shell 的重定向运算符将两个输出流重定向到终端上打印到的文件中:

curl -v https://duckduckgo.com > filename 2>&1
© www.soinside.com 2019 - 2024. All rights reserved.