Redirecting stdout from two programs

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












9














I'm running a memory check tool (prog1) on a C++ code (prog2), both of which give me a huge and detailed output. In order to chase down some bugs I need to save this output to a file.



I tried redirecting the stdout to a file:



prog1 prog2 > outfile.txt


But that gives me a file containing the output of prog2, while the output of prog1 is still going to the terminal.



Anyone know a way to specify that I want BOTH outputs to go to a file? Like (prog1 prog2) > outfile.txt?










share|improve this question




























    9














    I'm running a memory check tool (prog1) on a C++ code (prog2), both of which give me a huge and detailed output. In order to chase down some bugs I need to save this output to a file.



    I tried redirecting the stdout to a file:



    prog1 prog2 > outfile.txt


    But that gives me a file containing the output of prog2, while the output of prog1 is still going to the terminal.



    Anyone know a way to specify that I want BOTH outputs to go to a file? Like (prog1 prog2) > outfile.txt?










    share|improve this question


























      9












      9








      9







      I'm running a memory check tool (prog1) on a C++ code (prog2), both of which give me a huge and detailed output. In order to chase down some bugs I need to save this output to a file.



      I tried redirecting the stdout to a file:



      prog1 prog2 > outfile.txt


      But that gives me a file containing the output of prog2, while the output of prog1 is still going to the terminal.



      Anyone know a way to specify that I want BOTH outputs to go to a file? Like (prog1 prog2) > outfile.txt?










      share|improve this question















      I'm running a memory check tool (prog1) on a C++ code (prog2), both of which give me a huge and detailed output. In order to chase down some bugs I need to save this output to a file.



      I tried redirecting the stdout to a file:



      prog1 prog2 > outfile.txt


      But that gives me a file containing the output of prog2, while the output of prog1 is still going to the terminal.



      Anyone know a way to specify that I want BOTH outputs to go to a file? Like (prog1 prog2) > outfile.txt?







      command-line io-redirection stdout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 18 at 0:59









      muru

      1




      1










      asked Dec 17 at 12:16









      FJC

      1484




      1484




















          1 Answer
          1






          active

          oldest

          votes


















          19














          There’s a good chance that prog1 is writing its output to standard error. You can redirect both outputs to a single file with



          prog1 prog2 > outfile.txt 2>&1


          or you can split the outputs with



          prog1 prog2 > outfile.txt 2> errors.txt


          This doesn’t separate the individual programs’ output, it separates the output channels. See What are the shell's control and redirection operators? for details.



          If you look at prog1’s documentation, you might find an option to tell it to store its output in a named file instead. For example, with strace,



          strace -o strace.txt prog2 > outfile.txt


          would store strace’s output in strace.txt, and everything written to standard output in outfile.txt.






          share|improve this answer


















          • 5




            2>&1 has to go after > outfile.txt. Order of redirections matter.
            – Barmar
            Dec 17 at 17:14










          • Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
            – Morgen
            Dec 18 at 4:28










          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f489462%2fredirecting-stdout-from-two-programs%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









          19














          There’s a good chance that prog1 is writing its output to standard error. You can redirect both outputs to a single file with



          prog1 prog2 > outfile.txt 2>&1


          or you can split the outputs with



          prog1 prog2 > outfile.txt 2> errors.txt


          This doesn’t separate the individual programs’ output, it separates the output channels. See What are the shell's control and redirection operators? for details.



          If you look at prog1’s documentation, you might find an option to tell it to store its output in a named file instead. For example, with strace,



          strace -o strace.txt prog2 > outfile.txt


          would store strace’s output in strace.txt, and everything written to standard output in outfile.txt.






          share|improve this answer


















          • 5




            2>&1 has to go after > outfile.txt. Order of redirections matter.
            – Barmar
            Dec 17 at 17:14










          • Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
            – Morgen
            Dec 18 at 4:28















          19














          There’s a good chance that prog1 is writing its output to standard error. You can redirect both outputs to a single file with



          prog1 prog2 > outfile.txt 2>&1


          or you can split the outputs with



          prog1 prog2 > outfile.txt 2> errors.txt


          This doesn’t separate the individual programs’ output, it separates the output channels. See What are the shell's control and redirection operators? for details.



          If you look at prog1’s documentation, you might find an option to tell it to store its output in a named file instead. For example, with strace,



          strace -o strace.txt prog2 > outfile.txt


          would store strace’s output in strace.txt, and everything written to standard output in outfile.txt.






          share|improve this answer


















          • 5




            2>&1 has to go after > outfile.txt. Order of redirections matter.
            – Barmar
            Dec 17 at 17:14










          • Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
            – Morgen
            Dec 18 at 4:28













          19












          19








          19






          There’s a good chance that prog1 is writing its output to standard error. You can redirect both outputs to a single file with



          prog1 prog2 > outfile.txt 2>&1


          or you can split the outputs with



          prog1 prog2 > outfile.txt 2> errors.txt


          This doesn’t separate the individual programs’ output, it separates the output channels. See What are the shell's control and redirection operators? for details.



          If you look at prog1’s documentation, you might find an option to tell it to store its output in a named file instead. For example, with strace,



          strace -o strace.txt prog2 > outfile.txt


          would store strace’s output in strace.txt, and everything written to standard output in outfile.txt.






          share|improve this answer














          There’s a good chance that prog1 is writing its output to standard error. You can redirect both outputs to a single file with



          prog1 prog2 > outfile.txt 2>&1


          or you can split the outputs with



          prog1 prog2 > outfile.txt 2> errors.txt


          This doesn’t separate the individual programs’ output, it separates the output channels. See What are the shell's control and redirection operators? for details.



          If you look at prog1’s documentation, you might find an option to tell it to store its output in a named file instead. For example, with strace,



          strace -o strace.txt prog2 > outfile.txt


          would store strace’s output in strace.txt, and everything written to standard output in outfile.txt.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 17 at 17:59

























          answered Dec 17 at 12:19









          Stephen Kitt

          163k24365444




          163k24365444







          • 5




            2>&1 has to go after > outfile.txt. Order of redirections matter.
            – Barmar
            Dec 17 at 17:14










          • Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
            – Morgen
            Dec 18 at 4:28












          • 5




            2>&1 has to go after > outfile.txt. Order of redirections matter.
            – Barmar
            Dec 17 at 17:14










          • Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
            – Morgen
            Dec 18 at 4:28







          5




          5




          2>&1 has to go after > outfile.txt. Order of redirections matter.
          – Barmar
          Dec 17 at 17:14




          2>&1 has to go after > outfile.txt. Order of redirections matter.
          – Barmar
          Dec 17 at 17:14












          Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
          – Morgen
          Dec 18 at 4:28




          Note to future readers: @Barmar is absolutely correct that the relative order of redirections matter with respect to each other. For those less familiar, the order of redirections with respect to program arguments only matters in a few cases. The beginning and end are common locations, but the middle happens sometimes as well (please don't do this). echo >&2 hello world is equivalent to echo hello world >&2. More info here: tldp.org/LDP/abs/html/io-redirection.html
          – Morgen
          Dec 18 at 4:28

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489462%2fredirecting-stdout-from-two-programs%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

          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?