Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following script

screen -d -m -S $1                #start screen minimized
screen -S $1 -X stuff "$beast     
"                                 #stuff commands

unless I attach the screen first it seems the affects of stuff won't do anything? Why is this and how can I modify this script so I don't need to attach the screen?

share|improve this question

migrated from stackoverflow.com Oct 3 '11 at 11:52

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 10 down vote accepted

When you start a Screen session in detached mode (screen -d -m), no window is selected, so input later sent with screen -X stuff is just lost. You need to explicitly specify that you want to send the keystrokes to window 0 (-p 0). This is a good idea anyway, in case you happen to create other windows in that Screen session for whatever reason.

screen -S "$1" -p 0 -X stuff "$beast$(printf \\r)"

(printf \\r to strictly emulate the Return key; many but not all programs accept a newline (\n).)

share|improve this answer
    
Thanks! it works perfect. Sorry everyone for being off topic –  Kevin Duke Jun 2 '11 at 8:56

This recently came up while trying to answer a question on unix.stackexchange.com.

The summary is that screen does not have a default selected window unless you attatch, but Gilles showed us how you can force one to be selected by adding the argument -p 0 to your screen command.

Personally I recommend switching to tmux. Here is how you would port your screen commands to work in tmux:

tmux new-session -d -n $1
tmux send-keys -t $1 "$beast\n"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.