如何在tmux中获取send

编程入门 行业动态 更新时间:2024-10-26 20:29:03
本文介绍了如何在tmux中获取send-keys的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 05:08:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   tmux   send

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!