How do you capture the output of a closed tmux session or keep the session open after program exits?











up vote
0
down vote

favorite












if I do this:



tmux new-session -d -s test ls


is there a way to keep the session open after ls exits?



I would like to get the output later with this



tmux capture-pane -pt test


the same way that I can if I have a session that stays open like this



tmux new-session -d -s test "tail -f testfile.txt"


Or is there another way to capture the output of a session that already existed?










share|improve this question


























    up vote
    0
    down vote

    favorite












    if I do this:



    tmux new-session -d -s test ls


    is there a way to keep the session open after ls exits?



    I would like to get the output later with this



    tmux capture-pane -pt test


    the same way that I can if I have a session that stays open like this



    tmux new-session -d -s test "tail -f testfile.txt"


    Or is there another way to capture the output of a session that already existed?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      if I do this:



      tmux new-session -d -s test ls


      is there a way to keep the session open after ls exits?



      I would like to get the output later with this



      tmux capture-pane -pt test


      the same way that I can if I have a session that stays open like this



      tmux new-session -d -s test "tail -f testfile.txt"


      Or is there another way to capture the output of a session that already existed?










      share|improve this question













      if I do this:



      tmux new-session -d -s test ls


      is there a way to keep the session open after ls exits?



      I would like to get the output later with this



      tmux capture-pane -pt test


      the same way that I can if I have a session that stays open like this



      tmux new-session -d -s test "tail -f testfile.txt"


      Or is there another way to capture the output of a session that already existed?







      tmux






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 21:02









      Alex028502

      1,165616




      1,165616
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The easiest way would be to create the session without a specific command, and then call the command later. For instance:



          tmux new-session -d -s test
          tmux send-keys -t test "ls" Enter
          tmux capture pane -t test -p


          This is an odd use of tmux and it seems like nohup ls &>>~/mylog.out & might better match your goal.






          share|improve this answer





















          • because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
            – Alex028502
            Nov 20 at 8:17










          • You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
            – jeremysprofile
            Nov 20 at 16:35










          • I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
            – Alex028502
            Nov 20 at 16:47










          • stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
            – jeremysprofile
            Nov 20 at 16:56










          • It's good enough. It totally fixed my problem, but I usually wait anyhow.
            – Alex028502
            Nov 20 at 17:12











          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%2f53382574%2fhow-do-you-capture-the-output-of-a-closed-tmux-session-or-keep-the-session-open%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
          1
          down vote



          accepted










          The easiest way would be to create the session without a specific command, and then call the command later. For instance:



          tmux new-session -d -s test
          tmux send-keys -t test "ls" Enter
          tmux capture pane -t test -p


          This is an odd use of tmux and it seems like nohup ls &>>~/mylog.out & might better match your goal.






          share|improve this answer





















          • because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
            – Alex028502
            Nov 20 at 8:17










          • You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
            – jeremysprofile
            Nov 20 at 16:35










          • I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
            – Alex028502
            Nov 20 at 16:47










          • stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
            – jeremysprofile
            Nov 20 at 16:56










          • It's good enough. It totally fixed my problem, but I usually wait anyhow.
            – Alex028502
            Nov 20 at 17:12















          up vote
          1
          down vote



          accepted










          The easiest way would be to create the session without a specific command, and then call the command later. For instance:



          tmux new-session -d -s test
          tmux send-keys -t test "ls" Enter
          tmux capture pane -t test -p


          This is an odd use of tmux and it seems like nohup ls &>>~/mylog.out & might better match your goal.






          share|improve this answer





















          • because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
            – Alex028502
            Nov 20 at 8:17










          • You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
            – jeremysprofile
            Nov 20 at 16:35










          • I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
            – Alex028502
            Nov 20 at 16:47










          • stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
            – jeremysprofile
            Nov 20 at 16:56










          • It's good enough. It totally fixed my problem, but I usually wait anyhow.
            – Alex028502
            Nov 20 at 17:12













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          The easiest way would be to create the session without a specific command, and then call the command later. For instance:



          tmux new-session -d -s test
          tmux send-keys -t test "ls" Enter
          tmux capture pane -t test -p


          This is an odd use of tmux and it seems like nohup ls &>>~/mylog.out & might better match your goal.






          share|improve this answer












          The easiest way would be to create the session without a specific command, and then call the command later. For instance:



          tmux new-session -d -s test
          tmux send-keys -t test "ls" Enter
          tmux capture pane -t test -p


          This is an odd use of tmux and it seems like nohup ls &>>~/mylog.out & might better match your goal.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 0:11









          jeremysprofile

          1,5941516




          1,5941516












          • because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
            – Alex028502
            Nov 20 at 8:17










          • You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
            – jeremysprofile
            Nov 20 at 16:35










          • I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
            – Alex028502
            Nov 20 at 16:47










          • stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
            – jeremysprofile
            Nov 20 at 16:56










          • It's good enough. It totally fixed my problem, but I usually wait anyhow.
            – Alex028502
            Nov 20 at 17:12


















          • because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
            – Alex028502
            Nov 20 at 8:17










          • You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
            – jeremysprofile
            Nov 20 at 16:35










          • I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
            – Alex028502
            Nov 20 at 16:47










          • stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
            – jeremysprofile
            Nov 20 at 16:56










          • It's good enough. It totally fixed my problem, but I usually wait anyhow.
            – Alex028502
            Nov 20 at 17:12
















          because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
          – Alex028502
          Nov 20 at 8:17




          because I am using it with ffmpeg, and needed to send a 'q' to make the program stop. I think you can send a ctrl+c now, but the original blog post I followed used tmux and send 'q', so easiest just to keep using tmux. Only problem was it didn't show the output when it failed, but your solution works great.
          – Alex028502
          Nov 20 at 8:17












          You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
          – jeremysprofile
          Nov 20 at 16:35




          You can always stop any command running from the terminal with ctrl-c. Some other possible options to consider: using timeout if this is a timed command; using bg and fg; actually connecting to the tmux session and manually typing things and seeing the logs; using nohup as described and killing with ps. That being said, if my answer worked, you should accept it (click green checkmark by it) so that others know this question is resolved without having to click into it and read the whole thing.
          – jeremysprofile
          Nov 20 at 16:35












          I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
          – Alex028502
          Nov 20 at 16:47




          I think you are meant to wait a day or two before accepting an answer, especially when there are probably more possibilities. I already upvoted your answer.
          – Alex028502
          Nov 20 at 16:47












          stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
          – jeremysprofile
          Nov 20 at 16:56




          stackoverflow.com/help/someone-answers Waiting is not a requirement unless you are attempting to answer your own question, but you are right that you have no obligation to accept my answer if you feel it is not good enough.
          – jeremysprofile
          Nov 20 at 16:56












          It's good enough. It totally fixed my problem, but I usually wait anyhow.
          – Alex028502
          Nov 20 at 17:12




          It's good enough. It totally fixed my problem, but I usually wait anyhow.
          – Alex028502
          Nov 20 at 17:12


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f53382574%2fhow-do-you-capture-the-output-of-a-closed-tmux-session-or-keep-the-session-open%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

          Wiesbaden

          Marschland

          Dieringhausen