例外が無視されました: <_io.TextIOWrapper name=''モード='w'エンコーディング='UTF-8'>

例外が無視されました: <_io.TextIOWrapper name=''モード='w'エンコーディング='UTF-8'>

次のコード行を含むスクリプトがあります。

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

おすすめ記事