Click to See Complete Forum and Search --> : Stuffing a newline into a screen's input buffer


andysimmons
03-11-2004, 03:19 AM
Hi Guys. I'm using 'screen' to run a Soldier of Fortune 2 server, and I need to send a line of text to the detatched screen. I've figured out how to send everything except the newline character.
screen -S screen_name -X stuff "Some string goes here"
If I run the above command, and re-attach screen_name, I'll see Some string goes here, with my cursor right after the word 'here'. I've tried throwing a '\n' in a few places, but that either doesn't change a thing, or adds a literal \n to the string.

I've read everything I can find, but haven't even found a suggestion yet. Obviously, Googling for "screen" and "stuff" has taken me all over the Internet, with little relevant information. Any help would be greatly appreciated.

andysimmons
03-11-2004, 03:50 AM
Well, I found a workaround, but it requires 2 more lines.
echo "Some string goes here" > /some/temp/file
screen -S screen_name -X readreg a /some/temp/file
screen -S screen_name -X paste a
If anyone knows of a way to send a newline via 'stuff', I'm still curious, but no longer desparate :)

mindcooler
03-11-2004, 05:35 AM
man echo
echo -e "Some string goes here\n"
-e enable interpretation of the backslash-escaped characters

bwkaz
03-11-2004, 09:05 PM
Otherwise, man bash, especially the quoting features:

screen -S screen_name -X stuff 'Some string goes here
' Or, use $'...', like so:

screen -S screen_name -X stuff $'Some string goes here.\n' (the $ before the opening quote makes bash interpret the escape characters in the string, like echo -e would).

These all accomplish exactly the same thing, so your choice would depend on (basically) which one you like best. ;)

andysimmons
03-15-2004, 02:09 AM
Thanks guys!

Just FYI, a regular echo doesn't work, because I don't have a regular command prompt running on that screen. I have a game server running in the foreground on that screen, and I'm trying to send commands to the game's console. Echo might work with some piping, but bwkaz's methods already work perfectly, so I'll stick with them.

Anyway, thanks again for the help! That's much more elegant and efficient than my workaround.