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

南楼画角 提交于 2019-12-10 03:49:20

问题


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'

回答1:


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]



回答2:


one option is to call a script with send-keys that runs 'show info' and have the script 'send-keys' back the results to the tmux session you are on. this only works if you are in tmux to begin with.



来源:https://stackoverflow.com/questions/12665625/how-to-get-the-result-of-send-keys-in-tmux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!