Search code examples
tmux

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


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?


Solution

  • 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.