【问题标题】:Hide status output from jq in dos/windows在dos/windows中隐藏jq的状态输出
【发布时间】:2014-12-03 00:26:06
【问题描述】:

我使用 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,我在手册中找不到任何开关来禁用此输出。

有什么想法吗...?

非常感谢:)

【问题讨论】:

  • 如果这是在 stderr 中打印的,则可以使用 2>nul 进行重定向
  • curl.exe -H "Content-Type: application/json" -d ' {\"cmd\":\"login\"}' http://localhost:80/json | jq -r .session 2> nul 仍然显示它...
  • 1>nul 2>nul 呢?
  • 这看起来像是调用 curl 的输出。为 that 重定向 stderr。
  • 杰夫:就是这样!呃,我怎么可能没有注意到 :D 请提交答案,我会接受的:)

标签: json batch-file curl jq


【解决方案1】:
curl --silent
-s,--静音 静音或静音模式。不显示进度表或错误消息。使卷曲 沉默的。

【讨论】:

  • 可能想把--silent--show-error结合使用,否则如果出现连接错误什么的,你不会得到curl的任何错误提示
【解决方案2】:

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

示例

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

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

了解更多Curl Documentation

-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.

【讨论】:

    猜你喜欢
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 2016-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多