screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: screen -X stuff


From: Stephen LARROQUE
Subject: Re: screen -X stuff
Date: Thu, 29 Jul 2010 03:15:04 +0200

Hello guys,

I don't know if we talk about the same message Alexander, but the solution exists and was cited in the thread you talk about :

http://www.mail-archive.com/address@hidden/msg01084.html

quote :
"
This is because screen doesn't know which window to use for the
'exec' [or 'stuff'] command. Add '-p 0' and it should work.

Cheers,
Michael.
"

So you just have to add -p 0, it worked for me like a charm. To get the list of the windows, you can do -p = (man screen is your friend).

As a bonus, here is a snippet of my code :

function callconfig_screen { # a function is used to find the right screen because even if the name of the screen is supplied, there can be several screens with similar names, and we have then to process each screen by ourselves
local name=$1
local command=$2
for onescreen in $(screen -ls | grep -Eo "[0-9]+\.$name"); do
pressenter=$(echo -e "\r\n") # simulate pressing the enter key after the last command
screen -S $onescreen -p 0 -X stuff $"$command$pressenter" # screen -X executes screen commands, not normal commands. You then have to use some screen keywords, like _stuff $""_ or _window_ or such.
# Note : -p 0 is UTTERMOST IMPORTANT ! It specifies the window to which send the commands supplied in -X. By default, it will take the value of the last window you accessed (either a number or the name of the bin file), but if you didn't attach yet to this screen and spawned it as detached mode, then -X won't work, unless you specify -p 0 (or whatever window fits you, try with "-p =" to get a list or "-p -" to get a blank).
# Note 2 : -p 0 avoids the "A screen session started in detached mode cannot accept any 'stuff' commands unless the the session is first attached, and then re-detached." bug.
# For more infos, see : http://osdir.com/ml/gnu.screen.user/2007-07/msg00004.html and http://www.mail-archive.com/address@hidden/msg01084.html

# Standard way if the bash shell doesn't support stuff $"" :
#screen -S $onescreen -X stuff \
#"$(printf '%b' "$command$pressenter\015")" -p 0
if [ -n "$verbose" ]; then echo "screen -S $onescreen -X stuff $\"$command$pressenter\""; fi
done
}


Have a nice day,
Stephen L.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]