在屏幕中,如何向单个屏幕会话中的所有虚拟终端窗口发送命令?

发布于 2024-11-17 08:32:59 字数 1549 浏览 1 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘿看小鸭子会跑 2024-11-24 08:32:59

我在这里找到了一个很好的教程来执行此操作:

http://blog.cone.be/2009/11/24/gnu-screen-nethack- Different-screen-windows-sending-commands-to-all-screen-windows/

来自帖子:

一旦您习惯了多个窗口,您可能会遇到这样的情况:您想要向其中几个打开的窗口发送相同的命令。 Screen 中提供了“at”命令来执行此操作。首先,您需要打开命令行模式。

Ca:(冒号)进入命令行模式。

这样您可以输入一次命令,但您仍然需要输入每个单独的窗口。但还有更好的方法。作为示例,我们将向所有窗口发送“ls -l”。

在“#”处添加“ls -l^M”

这个命令几乎不可读,所以让我们把它拆开!第一部分是“at [identifier][#|*|%] command”。 at 命令将文本参数发送到您在标识符中指定的所有窗口。您可以将条件与窗口名称或编号(带 #)、用户名(带 *)或显示器(使用 %)相匹配。下一部分是您要在选定窗口中运行的命令。我们使用“stuff”将我们想要执行的命令填充到所选窗口的输入缓冲区中。事情真的很简单。它只是填充您作为参数提供的字符串。下一个问题是命令。或者更确切地说,让它被执行!要让屏幕在命令后面输入“enter”,要执行命令,请在末尾添加“^M”。您可以用它做更多的事情,而不仅仅是向输入发送 ls 。任何屏幕命令,例如重命名、移动窗口等等......都可以与“at”组合使用。

I found a good tutorial here to do this:

http://blog.cone.be/2009/11/24/gnu-screen-nethack-different-screen-windows-sending-commands-to-all-screen-windows/

From the post:

Once you re used to the multiple windows, you might run into a situation where you want to send a same command to several of these open windows. Screen provides in the “at” command to do this. First you ll need to open command line mode.

C-a : (colon) Enter command line mode.

This way you can type a command once, but you ll still have to enter each separate window. But there is a better way. As an example we ‘ll send “ls -l” to all the windows.

at "#" stuff "ls -l^M"

This command is barely readable, so let's pick it apart! The first part is 'at [identifier][#|*|%] command'. The at command sends the text parameter to all the windows you specified in the identifier. You can match the criteria to either the window name or number with #, the user name with * or the displays, using %. The next part is the command you want to run in the selected windows. We’re using "stuff" to stuff the command we want to execute into the input buffer of the selected windows. Stuff is really straightforward. It simply stuffs the string you gave as a parameter. Next problem is the command. Or rather having it executed! To get screen to put an “enter” after the command, to execute the command, add “^M” at the end. You can do a lot more with this than just sending an ls to the input. Any screen command, like renaming, moving windows around, whatnot .. is available in combination with "at".

街角迷惘 2024-11-24 08:32:59

抱歉回复迟了,但是 tmux 对您来说可能比 screen 更好。在tmux中,您必须按:Cb :进入命令模式并输入:setw Synchronize-panes(或者只是setw使用自动完成同步)。请注意,此命令启用窗格(一个分屏的区域,同时可见)之间的同步,但不能启用窗口(全屏、非分屏)之间的同步。

Sorry for this belated reply, but tmux might be a better choice for you than screen. In tmux, you have to press: C-b : to enter the command mode and input: setw synchronize-panes (or just setw sync<Tab> using autocompletion). Note that this command enables synchronization between panes (areas of one split screen, visible simultaneously), but not between windows (full, not split, screens).

南街九尾狐 2024-11-24 08:32:59

您可能还想仅发送到选定的窗口(多播)。

  1. 约定:将窗口标题的第一个字符赋予广播标志的含义。例如,如果标题以“.”开头然后窗口监听广播,否则不监听。
  2. 根据需要设置标题。

    screen -S SessionName -p 0 -X title "remote_0" # 窗口 0:忽略多播
    screen -S SessionName -p 1 -X title ".remote_1" # 窗口1:监听多播
    
  3. 通过screen的at命令发送内容给听众

    screen -S SessionName -X at ".#" stuff "date
    ”
    
  4. 注意:上面的结尾双引号确保发送 ^M (Cr)。

  5. 您可以通过这种方式启用/禁用基于窗口标题的多播。

You may also want to send to selected windows only (multicast).

  1. Convention: Give 1st character of window title the meaning of a broadcast flag. E.g. if title starts with "." then the window listens to broadcast, otherwise it doesn't.
  2. Set titles as needed.

    screen -S SessionName -p 0 -X title "remote_0"     # window 0: ignore multicast
    screen -S SessionName -p 1 -X title ".remote_1"    # window 1: listen to multicast
    
  3. Send contents to listeners with the at command of screen

    screen -S SessionName -X at ".#" stuff "date
    "
    
  4. Note: the ending double quote above ensures a ^M to be sent (Cr).

  5. You may enable / disable multicast based on window title this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文