Getting error code of the first command in pipe in ash

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I use wget to download a big file to two FIFOs like that:



wget <wget-args> -O - | tee -a "$fifo1" >> "$fifo2"


I want to retrieve the error code of wget on failure.



set -o pipefail returns error code of the rightmost command in a pipe so I can't be sure that the error code comes from wget.



So how can I do it in ash?







share|improve this question























    up vote
    1
    down vote

    favorite












    I use wget to download a big file to two FIFOs like that:



    wget <wget-args> -O - | tee -a "$fifo1" >> "$fifo2"


    I want to retrieve the error code of wget on failure.



    set -o pipefail returns error code of the rightmost command in a pipe so I can't be sure that the error code comes from wget.



    So how can I do it in ash?







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I use wget to download a big file to two FIFOs like that:



      wget <wget-args> -O - | tee -a "$fifo1" >> "$fifo2"


      I want to retrieve the error code of wget on failure.



      set -o pipefail returns error code of the rightmost command in a pipe so I can't be sure that the error code comes from wget.



      So how can I do it in ash?







      share|improve this question











      I use wget to download a big file to two FIFOs like that:



      wget <wget-args> -O - | tee -a "$fifo1" >> "$fifo2"


      I want to retrieve the error code of wget on failure.



      set -o pipefail returns error code of the rightmost command in a pipe so I can't be sure that the error code comes from wget.



      So how can I do it in ash?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 12 at 11:13









      K. Koovalsky

      103




      103




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Just redirect return code of wget to a file , here $? contains the return code



          $ (wget <wget-args> -O - ; echo $? > result) | tee -a "$fifo1" >> "$fifo2"


          Here the file result will contain the status code of your operation



          $ cat result
          0





          share|improve this answer























          • Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
            – K. Koovalsky
            Jul 12 at 12:57











          • I just replicated what you did, and tried giving you the return code of the first command
            – Arushix
            Jul 12 at 13:03










          • This won't work. The pipe is not getting any input, the ; ends the first command.
            – terdon♦
            Jul 12 at 13:43










          • That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
            – Kusalananda
            Jul 12 at 13:43











          • @Kusalananda please, post an answer and I'll accept it.
            – K. Koovalsky
            Jul 13 at 6:42










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454875%2fgetting-error-code-of-the-first-command-in-pipe-in-ash%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          Just redirect return code of wget to a file , here $? contains the return code



          $ (wget <wget-args> -O - ; echo $? > result) | tee -a "$fifo1" >> "$fifo2"


          Here the file result will contain the status code of your operation



          $ cat result
          0





          share|improve this answer























          • Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
            – K. Koovalsky
            Jul 12 at 12:57











          • I just replicated what you did, and tried giving you the return code of the first command
            – Arushix
            Jul 12 at 13:03










          • This won't work. The pipe is not getting any input, the ; ends the first command.
            – terdon♦
            Jul 12 at 13:43










          • That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
            – Kusalananda
            Jul 12 at 13:43











          • @Kusalananda please, post an answer and I'll accept it.
            – K. Koovalsky
            Jul 13 at 6:42














          up vote
          0
          down vote



          accepted










          Just redirect return code of wget to a file , here $? contains the return code



          $ (wget <wget-args> -O - ; echo $? > result) | tee -a "$fifo1" >> "$fifo2"


          Here the file result will contain the status code of your operation



          $ cat result
          0





          share|improve this answer























          • Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
            – K. Koovalsky
            Jul 12 at 12:57











          • I just replicated what you did, and tried giving you the return code of the first command
            – Arushix
            Jul 12 at 13:03










          • This won't work. The pipe is not getting any input, the ; ends the first command.
            – terdon♦
            Jul 12 at 13:43










          • That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
            – Kusalananda
            Jul 12 at 13:43











          • @Kusalananda please, post an answer and I'll accept it.
            – K. Koovalsky
            Jul 13 at 6:42












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Just redirect return code of wget to a file , here $? contains the return code



          $ (wget <wget-args> -O - ; echo $? > result) | tee -a "$fifo1" >> "$fifo2"


          Here the file result will contain the status code of your operation



          $ cat result
          0





          share|improve this answer















          Just redirect return code of wget to a file , here $? contains the return code



          $ (wget <wget-args> -O - ; echo $? > result) | tee -a "$fifo1" >> "$fifo2"


          Here the file result will contain the status code of your operation



          $ cat result
          0






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jul 13 at 6:45


























          answered Jul 12 at 12:43









          Arushix

          9968




          9968











          • Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
            – K. Koovalsky
            Jul 12 at 12:57











          • I just replicated what you did, and tried giving you the return code of the first command
            – Arushix
            Jul 12 at 13:03










          • This won't work. The pipe is not getting any input, the ; ends the first command.
            – terdon♦
            Jul 12 at 13:43










          • That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
            – Kusalananda
            Jul 12 at 13:43











          • @Kusalananda please, post an answer and I'll accept it.
            – K. Koovalsky
            Jul 13 at 6:42
















          • Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
            – K. Koovalsky
            Jul 12 at 12:57











          • I just replicated what you did, and tried giving you the return code of the first command
            – Arushix
            Jul 12 at 13:03










          • This won't work. The pipe is not getting any input, the ; ends the first command.
            – terdon♦
            Jul 12 at 13:43










          • That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
            – Kusalananda
            Jul 12 at 13:43











          • @Kusalananda please, post an answer and I'll accept it.
            – K. Koovalsky
            Jul 13 at 6:42















          Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
          – K. Koovalsky
          Jul 12 at 12:57





          Why is the stdout from wget passed further to tee and call to echo is kind'a transparent?
          – K. Koovalsky
          Jul 12 at 12:57













          I just replicated what you did, and tried giving you the return code of the first command
          – Arushix
          Jul 12 at 13:03




          I just replicated what you did, and tried giving you the return code of the first command
          – Arushix
          Jul 12 at 13:03












          This won't work. The pipe is not getting any input, the ; ends the first command.
          – terdon♦
          Jul 12 at 13:43




          This won't work. The pipe is not getting any input, the ; ends the first command.
          – terdon♦
          Jul 12 at 13:43












          That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
          – Kusalananda
          Jul 12 at 13:43





          That first part of the pipeline must run in a subshell so that the output of wget is piped to tee. ( wget ...; echo ... >result ) | tee ...
          – Kusalananda
          Jul 12 at 13:43













          @Kusalananda please, post an answer and I'll accept it.
          – K. Koovalsky
          Jul 13 at 6:42




          @Kusalananda please, post an answer and I'll accept it.
          – K. Koovalsky
          Jul 13 at 6:42












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454875%2fgetting-error-code-of-the-first-command-in-pipe-in-ash%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?