Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the result of send-keys in tmux?

Tags:

tmux

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'
like image 959
ssm2017 Avatar asked Sep 30 '12 22:09

ssm2017


1 Answers

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]
like image 64
Andy Pincombe Avatar answered Oct 06 '22 18:10

Andy Pincombe