在“屏幕"中,如何在单个屏幕会话中向所有虚拟终端窗口发送命令? [英] in Screen, how do I send a command to all virtual terminal windows within a single screen session?

查看:110
本文介绍了在“屏幕"中,如何在单个屏幕会话中向所有虚拟终端窗口发送命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在启动时如何在单个屏幕会话中创建多个窗口:

I know how to create multiple windows within a single screen session, at startup:

但是一旦我启动并运行它们,有什么方法可以将我的输入发送到所有打开的窗口,而不仅仅是当前的窗口?

But once I have them up and running, is there a way I can have my input be sent to all open windows, not just the one currently in focus?

推荐答案

我在这里找到了一个很好的教程来做到这一点:

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/

来自帖子:

一旦习惯了多个窗口,可能会遇到要向多个打开的窗口发送相同命令的情况.屏幕在"at"命令中提供了执行此操作的功能.首先,您需要打开命令行模式.

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 :(冒号)进入命令行模式.

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

这样,您可以一次键入命令,但仍然必须输入每个单独的窗口.但是有更好的方法.例如,我们将"ls -l"发送到所有窗口.

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.

在#"项"ls -l ^ M"处

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

该命令几乎不可读,所以让我们把它分开!第一部分是在[identifier] [#| * |%]命令中". at命令将text参数发送到您在标识符中指定的所有窗口.您可以使用%将条件与窗口名称或数字与#匹配,将用户名称与*或显示器匹配.下一部分是要在选定窗口中运行的命令.我们正在使用填充"将要执行的命令填充到所选窗口的输入缓冲区中.东西真的很简单.它只是填充您作为参数提供的字符串.下一个问题是命令.或者更确切地说,执行它!要使屏幕在命令后放置一个"enter"(输入),要执行该命令,请在末尾添加"^ M".除了向输入发送ls之外,您还可以做更多的事情.任何屏幕命令(例如重命名,四处移动窗口,什么都不能..)都可以与"at"组合使用.

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".

这篇关于在“屏幕"中,如何在单个屏幕会话中向所有虚拟终端窗口发送命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆