开发者

in Screen, how do I send a command to all virtual terminal windows within a single screen session? [closed]

开发者 https://www.devze.com 2023-03-16 03:56 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Closed 8 years ago.

开发者_JAVA百科 Improve this question

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/

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消