我正在使用Google Cloud SDK CLI( gcloud命令),该命令非常棒! 尽pipe我想输出JSON格式的Google Compute Engine实例列表(通过运行gcloud compute instances list --format json格式gcloud compute instances list --format json )并使用jq JSON处理器对其进行过滤,但该命令有时会输出以下消息:
Updates are available for some Cloud SDK components. To install them, please run: $ gcloud components update
我知道这个消息很重要,但是我想将JSON输出视为格式良好的。 有没有办法抑制这个消息? -q和--verbosity none选项不起作用。
您可以使用以下命令禁用更新检查:
gcloud config set component_manager/disable_update_check true
但是,您的用例仍然适用于更新消息。 你真的看到JSONparsing器的问题吗? 预期的行为是JSON输出转到标准输出,更新消息转到标准错误。
$ gcloud compute instances list --format=json > stdout.log 2> stderr.log $ cat stderr.log Updates are available for some Cloud SDK components. To install them, please run: $ gcloud components update $ cat stdout.log { // JSON here // ... }
这将让你用如下的调用parsingJSON:
gcloud compute instances list --format=json | python -m json.tool # substitute your tool of choice here