Change stdout/stderr output device

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











up vote
0
down vote

favorite












By default if we run



foo()
echo "myfoo"



it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't automatically write to stdout?



maybe something like this:



foo()
mkfifo bar
exec 1<>bar
echo "myfoo" # this gets written to the bar named pipe?



so we "repoint" stdout somewhere else perhaps?







share|improve this question



















  • yeah that doesn't seem to work. If i run tail -f bar I don't seem to get any data there.
    – Alexander Mills
    May 8 at 4:40










  • Are you asking for something very different from foo >bar?
    – Kusalananda
    May 8 at 4:58










  • @Kusalananda honestly, I might delete this question, this new question is better: unix.stackexchange.com/questions/442461/…
    – Alexander Mills
    May 8 at 4:59














up vote
0
down vote

favorite












By default if we run



foo()
echo "myfoo"



it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't automatically write to stdout?



maybe something like this:



foo()
mkfifo bar
exec 1<>bar
echo "myfoo" # this gets written to the bar named pipe?



so we "repoint" stdout somewhere else perhaps?







share|improve this question



















  • yeah that doesn't seem to work. If i run tail -f bar I don't seem to get any data there.
    – Alexander Mills
    May 8 at 4:40










  • Are you asking for something very different from foo >bar?
    – Kusalananda
    May 8 at 4:58










  • @Kusalananda honestly, I might delete this question, this new question is better: unix.stackexchange.com/questions/442461/…
    – Alexander Mills
    May 8 at 4:59












up vote
0
down vote

favorite









up vote
0
down vote

favorite











By default if we run



foo()
echo "myfoo"



it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't automatically write to stdout?



maybe something like this:



foo()
mkfifo bar
exec 1<>bar
echo "myfoo" # this gets written to the bar named pipe?



so we "repoint" stdout somewhere else perhaps?







share|improve this question











By default if we run



foo()
echo "myfoo"



it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't automatically write to stdout?



maybe something like this:



foo()
mkfifo bar
exec 1<>bar
echo "myfoo" # this gets written to the bar named pipe?



so we "repoint" stdout somewhere else perhaps?









share|improve this question










share|improve this question




share|improve this question









asked May 8 at 4:36









Alexander Mills

1,885929




1,885929











  • yeah that doesn't seem to work. If i run tail -f bar I don't seem to get any data there.
    – Alexander Mills
    May 8 at 4:40










  • Are you asking for something very different from foo >bar?
    – Kusalananda
    May 8 at 4:58










  • @Kusalananda honestly, I might delete this question, this new question is better: unix.stackexchange.com/questions/442461/…
    – Alexander Mills
    May 8 at 4:59
















  • yeah that doesn't seem to work. If i run tail -f bar I don't seem to get any data there.
    – Alexander Mills
    May 8 at 4:40










  • Are you asking for something very different from foo >bar?
    – Kusalananda
    May 8 at 4:58










  • @Kusalananda honestly, I might delete this question, this new question is better: unix.stackexchange.com/questions/442461/…
    – Alexander Mills
    May 8 at 4:59















yeah that doesn't seem to work. If i run tail -f bar I don't seem to get any data there.
– Alexander Mills
May 8 at 4:40




yeah that doesn't seem to work. If i run tail -f bar I don't seem to get any data there.
– Alexander Mills
May 8 at 4:40












Are you asking for something very different from foo >bar?
– Kusalananda
May 8 at 4:58




Are you asking for something very different from foo >bar?
– Kusalananda
May 8 at 4:58












@Kusalananda honestly, I might delete this question, this new question is better: unix.stackexchange.com/questions/442461/…
– Alexander Mills
May 8 at 4:59




@Kusalananda honestly, I might delete this question, this new question is better: unix.stackexchange.com/questions/442461/…
– Alexander Mills
May 8 at 4:59










1 Answer
1






active

oldest

votes

















up vote
0
down vote













This technique will probably do the trick:
Using process substitution, only send stderr to process



Basically, you call:



exec > $some_file


using process substitution, you can do something like:



exec > >( while read line; do echo " stdout: $line"; done )


that means that all stdout will go to that file instead of to the terminal.






share|improve this answer





















    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%2f442460%2fchange-stdout-stderr-output-device%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













    This technique will probably do the trick:
    Using process substitution, only send stderr to process



    Basically, you call:



    exec > $some_file


    using process substitution, you can do something like:



    exec > >( while read line; do echo " stdout: $line"; done )


    that means that all stdout will go to that file instead of to the terminal.






    share|improve this answer

























      up vote
      0
      down vote













      This technique will probably do the trick:
      Using process substitution, only send stderr to process



      Basically, you call:



      exec > $some_file


      using process substitution, you can do something like:



      exec > >( while read line; do echo " stdout: $line"; done )


      that means that all stdout will go to that file instead of to the terminal.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        This technique will probably do the trick:
        Using process substitution, only send stderr to process



        Basically, you call:



        exec > $some_file


        using process substitution, you can do something like:



        exec > >( while read line; do echo " stdout: $line"; done )


        that means that all stdout will go to that file instead of to the terminal.






        share|improve this answer













        This technique will probably do the trick:
        Using process substitution, only send stderr to process



        Basically, you call:



        exec > $some_file


        using process substitution, you can do something like:



        exec > >( while read line; do echo " stdout: $line"; done )


        that means that all stdout will go to that file instead of to the terminal.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered May 8 at 4:50









        Alexander Mills

        1,885929




        1,885929






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442460%2fchange-stdout-stderr-output-device%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?