I have been trying to send commands to a running gnu screen session (4.00.03) in opensolaris, but cannot get it to run any commands through any combination of screen -X

Ok, I start a screen session with screen -S test, and then tried to with screen -r -X "date"to just show me the date, when I would reconnect to it. But neither an error message nor output in the screen happened. I tried with so many combinations, that I can't even remember.

Any hints on how to accomplish it?

The reason why I am doing this is, because I have a program, which does not come as a daemon, and I wish to start it in a screen session, so I can later on see what is going on.

link|improve this question
Belongs on superuser ? – Paul R Mar 5 '10 at 9:05
I tried it only with the superuser so far hmm, will give it a go with a local user. – aXon Mar 5 '10 at 10:21
Ok, tried it with a local user, same thing happens - nothing. – aXon Mar 5 '10 at 10:38
it seems, as if this "command" that they are talking about in the man pages is meant for a screen command, like settings for the screen session itself. Rather than sending commands for the shell, which is opened in the screen session. So, anyone an idea of how to make it happen with a bash script?? – aXon Mar 5 '10 at 11:29
@Axon: Yes, -X sends screen commands, not shell commands, but screen has a command 'screen' which can open new screen windows. – Roger Pate Mar 5 '10 at 20:43
feedback

migrated from stackoverflow.com Mar 5 '10 at 23:40

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

2 Answers

Actually it's quite simple. You can use the following:

screen -S sessionname -X stuff 'command'`echo -ne '\015'`

echo -ne '\015' emulates pressing the Enter key.

link|improve this answer
feedback

Sounds like you want:

$ screen -S test -d -m -c /dev/null -- sh -c 'date; exec $SHELL'

-S test: name this session
-d -m: start screen detached
-c /dev/null: ignore ~/.screenrc (provide a different file or drop this option,
  as needed)
--: end of screen options
sh -c 'date; exec $SHELL': command for screen to run, note that if this command
  was just 'date' then screen would exit immediately.  if you don't want to exit
  screen after your command exits, then you might use:
    $ screen -S test -d -m -c /dev/null -- your command here

Or maybe you just want dtach.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown