I am using tmux to run a server console. To check whether the console is answering, I would like to use send-keys
to run a command on the console:
tmux send-keys -t mysess:mywin "show info" Enter
(Actually, I’m currently logging the full console output to a file and reading the last line, but I hope that a better solution exists.)
tmux pipe-pane -o -t mysess:mywin 'cat >> mysess-mywin.log'
The context of how you are accessing the output will impact whether this solution is better or not, but this might work:
tmux send-keys -t <session:win.pane> '<command>' Enter
tmux capture-pane -t <session:win.pane>
tmux show-buffer
You should be able to play with the -S
, and -E
options of capture-pane
, as well as the size of the pane, to accurately capture the output. If you're so inclined, you could also use show-panes
and a small regexp to capture the height of the pane, and then just use -S <height - 1>
to capture just the last line.
It's then simple to read this from another program like so (e.g., in python):
print Popen(['tmux', 'show-buffer'], stdout=PIPE).communicate()[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With