Possible Duplicate:sending text input to a detached screen With reference to the answered question: Sending input to a screen session from outsideI am trying to write a script that will create a screen and then stuff input (in my case, UNIX commands) into the shell that I want it to execute.Here's what I have till now:$ screen -dmS new_screen bash$ screen -S new_screen -X stuff cd /some/path/some_script_file.sh <--This new line is required to execute the above command. $ # Note: See comments. We could insert the newline character instead of 'hard-coding' a newline string literal.For some reason, the screen gets created fine and enters the bash shell. But the cd and some_script_file.sh commands don't get stuffed to the screen's bash shell. Now the really strange part is.. After I detach from the screen, re-execute the stuff command as below..$ screen -S new_screen -X stuff cd /some/path/some_script_file.shand then attach back into new_screen. Now I see that the commands were correctly stuffed and executed in the bash shell inside screen.Not sure where I am going wrong here, there seems to be any issue stuff-ing commands into a not as yet attached screen.
Unable to 'stuff' commands into a created 'screen' immediately after creating it
gnu screen
When a screen session is first created, no window is selected. As such, when you send your commands, screen doesn't know which window to send it to. Once you have attached to the screen, however, the window has become selected, which is why you can send commands after doing so. To select a window from the command line you need to use the -p option.Here's a modification of your command that should work:screen -S new_screen -p 0 -X stuff cd /some/path/some_script_file.sh