I can run a command in a detached tmux session with:
tmux new -d 'while true; do date; sleep 1; done'
I can run a command in an attached tmux session and log the console output with:
tmux new 'while true; do date; sleep 1; done' \; pipe-pane 'bzip2 > /tmp/log.bz2'
But how can I run a command in a detached tmux session AND log the console output? The following runs a command in a detached tmux session, but silently fails to log the output:
tmux new -d 'while true; do date; sleep 1; done' \; pipe-pane 'bzip2 > /tmp/log.bz2'
The closest I've been able to get is the following, which starts the command in a non-detached tmux, starts logging, and then detaches:
tmux new 'while true; do date; sleep 1; done' pipe-pane 'bzip2 > /tmp/log.bz2' \; detach
This works, but prints the following gibberish onto the console after:
^[[?62;9;c
What is the right way of doing this?
tee
may be your friend while figuring it all out.