异常被忽略:

异常被忽略:

我有一个包含以下代码行的脚本:

currentTenantId="$(az account show --query tenantId | jq -r 2>/dev/null)"

该行给我以下错误消息:

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

我把它分解并尝试了这个:

az account show --query tenantId                                 #OK - no errors
az account show --query tenantId | jq -r 2>/dev/null             #OK - no errors
"$(az account show --query tenantId | jq -r 2>/dev/null)"        #NOT OK - same error as mentioned above

附加信息:当我运行这个(并且不将结果放入变量中)时:

"$(az account show --query tenantId | jq -r 2>/dev/null)"

我得到:

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

Command '' not found, but can be installed with:

sudo apt install libpam-mount
sudo apt install openssh-server
sudo apt install openvswitch-common
sudo apt install openvswitch-switch
sudo apt install php-common
sudo apt install bpfcc-tools
sudo apt install burp
sudo apt install cryptmount
sudo apt install dolphin-emu
sudo apt install mailutils-mh
sudo apt install mmh
sudo apt install nmh

该脚本用于其他几个客户端并适用于其他客户端。所以我不想对脚本进行任何更改,但由于它适用于其他客户端,我认为它应该是我的客户端上缺少的东西。你们中的任何人都可以引导我朝任何方向解决这个问题吗?

我运行的是 Ubuntu 18.04。


当我跑步时:

currentTenantId="$(az account show --query tenantId | jq -r)"

我得到:

jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options] <jq filter> [file...]

        jq is a tool for processing JSON inputs, applying the
        given filter to its JSON text inputs and producing the
        filter's results as JSON on standard output.
        The simplest filter is ., which is the identity filter,
        copying jq's input to its output unmodified (except for
        formatting).
        For more advanced filters see the jq(1) manpage ("man jq")
        and/or https://stedolan.github.io/jq

        Some of the options include:
         -c             compact instead of pretty-printed output;
         -n             use `null` as the single input value;
         -e             set the exit status code based on the output;
         -s             read (slurp) all inputs into an array; apply filter to it;
         -r             output raw strings, not JSON texts;
         -R             read raw strings, not JSON texts;
         -C             colorize JSON;
         -M             monochrome (don't colorize JSON);
         -S             sort keys of objects on output;
         --tab  use tabs for indentation;
         --arg a v      set variable $a to value <v>;
         --argjson a v  set variable $a to JSON value <v>;
         --slurpfile a f        set variable $a to an array of JSON texts read from <f>;
        See the manpage for more options.
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

答案1

解决办法:原来是命令错误。它应该是这样的:

currentTenantId="$(az account show --query tenantId 2>/dev/null | jq -r .)"

相关内容