Keith's answer does the job, but binds the window to this process, so that as soon as the application is completed, the window closes.
Here is what I did while working perfectly:
screen -t "RAILS SERVER" stuff "cd $my_rails_directory; rails server^M" screen -t "RAILS CONSOLE" stuff "cd $my_rails_directory; rails console^M"
The important part here is the ^ M character. This is actually not ^ followed by M. This is a raw newline character. In almost any CLI program (vi, emacs, shell), you can press CTRL-V and then press ENTER to create this character.
How it works? The stuff command enters this line directly into the console. The newline literal at the end actually sends the command as usual if you typed it yourself. Hope this helps! I found this approach much more stable and reliable than others.
source share