13

我正在使用 curl for windows ( http://www.confusedbycode.com/curl/ ) 和 jq ( http://stedolan.github.io/jq/ ) 通过批处理文件与 web api 交互。我遇到的看似简单的问题是,无论我做什么,我似乎都无法抑制 JQ 的“状态”输出。特别是,它总是输出“进度状态”,例如:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100   116  100    99  100    17    908    155 --:--:-- --:--:-- --:--:--   908

一个简化的示例批处理文件将是:

@echo off
@curl.exe -H "Content-Type: application/json" -d '{\"cmd\":\"login\"}' http://localhost:80/json | jq -r .session > sess.txt

请注意 jq 确实按预期运行 - 我只需要让它静默运行。它似乎忽略了@echo off,并且我在手册中找不到任何开关来禁用此输出。

有任何想法吗...?

提前非常感谢:)

4

2 回答 2

28
curl --silent
-s,--静音
  静音或静音模式。不显示进度表或错误消息。使卷曲
  沉默的。
于 2014-12-03T07:15:04.950 回答
1

解决方法:为了去掉curl restful api response上的进度条,使用--silentflag(简称-s)或者使用--no-progress-meter. 我建议使用后者,因为您希望收到有关不良响应的警告和信息性消息。

例子

1. curl -s <Web-Address>curl --silent <Web-Address>

2. curl --no-progress-meter <Web-Address>

更多卷曲文档

-s, --silent

Silent or quiet mode. Don't show progress meter or error messages. 
Makes Curl mute. 
It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

Use -S, --show-error in addition to this option to disable progress meter but still show error messages.

--no-progress-meter

Option to switch off the progress meter output without muting or otherwise affecting warning and informational messages like -s, --silent does.

Note that this is the negated option name documented. You can thus use --progress-meter to enable the progress meter again.
于 2020-05-13T14:43:11.453 回答