我正在使用tmux运行服务器控制台。为了检查控制台是否有响应,我想使用send-keys
在控制台上运行一个命令:
tmux send-keys -t mysess:mywin "show info" Enter
实际上,我目前正在将完整的控制台输出记录到文件中并读取最后一行,但我希望存在更好的解决方案。
tmux pipe-pane -o -t mysess:mywin 'cat >> mysess-mywin.log'
我正在使用tmux运行服务器控制台。为了检查控制台是否有响应,我想使用send-keys
在控制台上运行一个命令:
tmux send-keys -t mysess:mywin "show info" Enter
实际上,我目前正在将完整的控制台输出记录到文件中并读取最后一行,但我希望存在更好的解决方案。
tmux pipe-pane -o -t mysess:mywin 'cat >> mysess-mywin.log'
您访问输出的方式将影响此解决方案是否更好,但这可能有效:
tmux send-keys -t <session:win.pane> '<command>' Enter
tmux capture-pane -t <session:win.pane>
tmux show-buffer
capture-pane
的-S
和-E
选项,以及窗格的大小,来准确地捕获输出。如果您愿意,还可以使用show-panes
和一个小的正则表达式来捕获窗格的高度,然后只需使用-S <height - 1>
来捕获最后一行。print Popen(['tmux', 'show-buffer'], stdout=PIPE).communicate()[0]
show-panes
是什么意思,但是可以使用 tmux ... capture-pane | tail -1
来获取最后一行。 - Ryan Chen一个选项是使用send-keys调用“show info”脚本,并让脚本将结果“send-keys”回您正在使用的tmux会话。这仅在您最初就在tmux中时才有效。