问题描述
限时送ChatGPT账号..我正在使用 tmux 来运行服务器控制台.要检查控制台是否正在应答,我想使用 send-keys
在控制台上运行命令:
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
您应该可以使用 capture-pane
的 -S
和 -E
选项,以及窗格,以准确捕获输出.如果您愿意,也可以使用 show-panes
和一个小的正则表达式来捕获窗格的高度,然后只需使用 -S
只捕获最后一行.
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.
然后很容易从另一个程序中读取它(例如,在 python 中):
It's then simple to read this from another program like so (e.g., in python):
print Popen(['tmux', 'show-buffer'], stdout=PIPE)municate()[0]
这篇关于如何在tmux中获取send-keys的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论