How to get the result of sending keys in tmux?

I use tmux to start the server console. To check if the console is responding, I would like to use send-keys to run the command on the console:

 tmux send-keys -t mysess:mywin "show info" Enter 

(In fact, Im currently logging the full console output to a file and reading the last line, but I hope a better solution exists.)

 tmux pipe-pane -o -t mysess:mywin 'cat >> mysess-mywin.log' 
+6
source share
2 answers

The context of how you access the result will affect whether this solution is better or not, but it 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 capture-pane options, as well as the panel size, to accurately display the output. If you are so prone, you can also use show-panes and a small regular expression to capture the height of the panel, and then just use -S <height - 1> to capture only the last line.

Then it is easy to read this from another program, for example (e.g. in python):

 print Popen(['tmux', 'show-buffer'], stdout=PIPE).communicate()[0] 
+4
source

one option is to invoke a script using send-keys, which launches "show info" and has the script "send-keys" return the results to the tmux session you are in. this only works if you start with tmux.

0
source

Source: https://habr.com/ru/post/926632/


All Articles