Help - Search - Members - Calendar
Full Version: Screen Help
Linuxhelp > Support > Technical Support
jedihawk
Greetings all,

I'm having trouble giving a detached screen a command from another shell. Is this possible?

Here's what I've done:

In window 1, I setup a screen like this:

CODE
$ screen -d -m -S hawktest01


This starts a bash shell in a detached screen, and it appears in the screen list:

CODE
$ screen -ls
There is a screen on:
       25704.hawktest01        (Detached)
1 Socket in /home/jedihawk/.screen.


Now, if I attach to it like this:

CODE
$ screen -r hawktest01


I get the screen session and my bash prompt and all is well. Then I hit Ctrl-A D to detach and I'm back where I was.

From window 2, I run:

CODE
$ screen -S hawktest01 -X readreg 1 hawk


This sends a command to the screen with the name 'hawktest01', which I just setup in window 1. The command tells screen to read the contents of the file 'hawk' and put it into register 1, which is just a temporary user space, like a copy buffer. The contents of the file 'hawk' is 'hawk'; I'm keeping this simple.

I follow this command with another:

CODE
$ screen -S hawktest01 -X process 1


This command puts the contents of register 1 into the keyboard buffer, as if the user had typed it.

The problem is that if the screen in window 1 is detached, the above two commands don't work--but they also don't give any indication that they didn't work.

If, however, I re-attach to the screen session in window 1:

CODE
$ screen -r hawktest01


And then I run the above two commands again from window 2:

CODE
$ screen -S hawktest01 -X readreg 1 hawk
$ screen -S hawktest01 -X process 1


The word 'hawk' appears in window 1, as it should. Basically, I'm commanding another screen session from remote (but I'm on the same machine). This procedure doesn't seem to work if if the screen session in window 1 is detached.

Is it possible to send commands to a detached screen session?

-Hawk
jedihawk
Well, it seems that commanding a detached screen from another terminal won't work unless using something like:

CODE
screen -S hawktest01 -X exec .!. echo ls


But this opens up a subprocess which pipes the output to the shell, which won't work for my purposes because I'm trying to run a program with an interactive macro.

However, if I setup a series of commands which switch virtual windows within the same screen session, then all works very well. For example, I have two virtual windows open, then I run my script from virtual window 0 and it's setup to switch to virtual window 1 and run the program. That's good because I can watch what's happening as it goes along.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.