0

I have a script with the following code line:

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

This line gives me the following error message:

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

I broke it down and tried this:

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

Additional info: When i run just this (and not putting the result into a variable):

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

I get:

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

This script is used on several other clients and works on other clients. So I'm not looking to do any changes in the script, but since it works on other clients I think it should be something on my client that's missing. Can any of you lead me in any direction to solve this?

I'm running Ubuntu 18.04.


When I run:

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

I get:

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
7
  • Can you repeatedly run az account show --query tenantId | jq -r 2>/dev/null (let's say 10 times in a row) and confirm there are no errors? Nov 27 '20 at 13:24
  • Yes, works every time
    – ELU
    Nov 27 '20 at 13:28
  • 1
    I'm assuming this is because you're not giving jq a filter. Try using . as the filter, i.e. jq -r .. This would act as the identity filter and would just reformat the JSON document. In later versions of jq, this is the default behavior, but release 1.5 may need this explicitly. Not turning this into an answer as the question never says anything about what you are expecting jq to do.
    – Kusalananda
    Nov 30 '20 at 20:20
  • @Kusalananda, This: currentTenantId="$(az account show --query tenantId | jq -r .)" ...works fine
    – ELU
    Dec 1 '20 at 6:33
  • 1
    @ELU I mentioned a possible cause already, the version of jq. Version 1.5 does not use the identity filter by default, but 1.6 does.
    – Kusalananda
    Dec 1 '20 at 13:46
0

Solution: Turned out that the command was wrong. This is how it should look like:

currentTenantId="$(az account show --query tenantId 2>/dev/null | jq -r .)"
3
  • What is this az command, by the way? I ran it on my Ubuntu 18.04 and didn't get a hint about it. I guess it's some Python script? (I'm guessing this because I got this error message from my Python script.)
    – yaobin
    Dec 20 '20 at 1:22
  • This discussion may be helpful, too.
    – yaobin
    Dec 20 '20 at 1:37
  • az is Azure command line interface tool, to control all your resources in azure.
    – Nik
    Aug 6 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.