Get bash sub shell output immediately from named pipe











up vote
0
down vote

favorite












I have a few commands i run between brackets which i then redirect to a named pipe and tail the pipe however it looks like the redirection happens only after the block has finished executing as i don't see any output from the tail command for a while and it only shows the last command ouput when i do. Any ideas how view the output of the block in realtime?



Example Script



#!/usr/bin/env bash

mkfifo /tmp/why_you_no_out;
trap "rm /tmp/why_you_no_out" 0;

{
for ((i=1;i<=100;i++)); do
printf "$i";
done
sleep 10s;
printf "n12356";
} >> /tmp/why_you_no_out &

printf "here";

tail -n 1 -f /tmp/why_you_no_out









share|improve this question




























    up vote
    0
    down vote

    favorite












    I have a few commands i run between brackets which i then redirect to a named pipe and tail the pipe however it looks like the redirection happens only after the block has finished executing as i don't see any output from the tail command for a while and it only shows the last command ouput when i do. Any ideas how view the output of the block in realtime?



    Example Script



    #!/usr/bin/env bash

    mkfifo /tmp/why_you_no_out;
    trap "rm /tmp/why_you_no_out" 0;

    {
    for ((i=1;i<=100;i++)); do
    printf "$i";
    done
    sleep 10s;
    printf "n12356";
    } >> /tmp/why_you_no_out &

    printf "here";

    tail -n 1 -f /tmp/why_you_no_out









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a few commands i run between brackets which i then redirect to a named pipe and tail the pipe however it looks like the redirection happens only after the block has finished executing as i don't see any output from the tail command for a while and it only shows the last command ouput when i do. Any ideas how view the output of the block in realtime?



      Example Script



      #!/usr/bin/env bash

      mkfifo /tmp/why_you_no_out;
      trap "rm /tmp/why_you_no_out" 0;

      {
      for ((i=1;i<=100;i++)); do
      printf "$i";
      done
      sleep 10s;
      printf "n12356";
      } >> /tmp/why_you_no_out &

      printf "here";

      tail -n 1 -f /tmp/why_you_no_out









      share|improve this question















      I have a few commands i run between brackets which i then redirect to a named pipe and tail the pipe however it looks like the redirection happens only after the block has finished executing as i don't see any output from the tail command for a while and it only shows the last command ouput when i do. Any ideas how view the output of the block in realtime?



      Example Script



      #!/usr/bin/env bash

      mkfifo /tmp/why_you_no_out;
      trap "rm /tmp/why_you_no_out" 0;

      {
      for ((i=1;i<=100;i++)); do
      printf "$i";
      done
      sleep 10s;
      printf "n12356";
      } >> /tmp/why_you_no_out &

      printf "here";

      tail -n 1 -f /tmp/why_you_no_out






      bash named-pipes tail subshell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 14:44









      Aserre

      3,28532043




      3,28532043










      asked Nov 8 at 11:05









      Snipzwolf

      298516




      298516
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Sounds like the issue is buffering. Most shells don't want to write data a byte at a time because it's wasteful. Instead, they wait until they have a sizable chunk of data before committing it unless the output is connected to your terminal.



          If you're looking to unbuffer the output of an arbitrary command, you may find the "unbuffer" utility helpful or any of the solutions mentioned in this question: How to make output of any shell command unbuffered?



          If you're dealing with specific applications, they may have options to reduce buffering. For example, GNU's grep includes the --line-buffered option.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206461%2fget-bash-sub-shell-output-immediately-from-named-pipe%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Sounds like the issue is buffering. Most shells don't want to write data a byte at a time because it's wasteful. Instead, they wait until they have a sizable chunk of data before committing it unless the output is connected to your terminal.



            If you're looking to unbuffer the output of an arbitrary command, you may find the "unbuffer" utility helpful or any of the solutions mentioned in this question: How to make output of any shell command unbuffered?



            If you're dealing with specific applications, they may have options to reduce buffering. For example, GNU's grep includes the --line-buffered option.






            share|improve this answer

























              up vote
              0
              down vote













              Sounds like the issue is buffering. Most shells don't want to write data a byte at a time because it's wasteful. Instead, they wait until they have a sizable chunk of data before committing it unless the output is connected to your terminal.



              If you're looking to unbuffer the output of an arbitrary command, you may find the "unbuffer" utility helpful or any of the solutions mentioned in this question: How to make output of any shell command unbuffered?



              If you're dealing with specific applications, they may have options to reduce buffering. For example, GNU's grep includes the --line-buffered option.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Sounds like the issue is buffering. Most shells don't want to write data a byte at a time because it's wasteful. Instead, they wait until they have a sizable chunk of data before committing it unless the output is connected to your terminal.



                If you're looking to unbuffer the output of an arbitrary command, you may find the "unbuffer" utility helpful or any of the solutions mentioned in this question: How to make output of any shell command unbuffered?



                If you're dealing with specific applications, they may have options to reduce buffering. For example, GNU's grep includes the --line-buffered option.






                share|improve this answer












                Sounds like the issue is buffering. Most shells don't want to write data a byte at a time because it's wasteful. Instead, they wait until they have a sizable chunk of data before committing it unless the output is connected to your terminal.



                If you're looking to unbuffer the output of an arbitrary command, you may find the "unbuffer" utility helpful or any of the solutions mentioned in this question: How to make output of any shell command unbuffered?



                If you're dealing with specific applications, they may have options to reduce buffering. For example, GNU's grep includes the --line-buffered option.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 14:51









                Mr. Llama

                15.3k23776




                15.3k23776






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206461%2fget-bash-sub-shell-output-immediately-from-named-pipe%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Schultheiß

                    Verwaltungsgliederung Dänemarks

                    Liste der Kulturdenkmale in Wilsdruff