I am using screen like this:

screen -L -dm -S session1 -c "./game_server -options"

to wrap around game servers. I log their output to a file, and can send them input with:

screen -r session1 -p0 -X "stuff \"this into input^M\""

The timeout between log file flushes can be specified in the configuration file (10 seconds in my case).

The problem I have is that I can't force screen to flush output to the logfile. For example after I send a "status" command to a game server, the game server prints some info, but it takes at least 10 seconds to add that to the log file. I have tried sending:

screen -r session1 -p0 -X "logfile flush 1"

But it doesn't react to that. I've also tried flush 0 with no luck. I wouldn't want to always log with a timeout of 1 second, it's only really needed after receiving a command. Note that I'm paranoid about performance here because the session is running a game server after all.

How can I force screen to flush output to the logfile? Is there a way to do what I need (log output to file and send commands to input) other than with screen, maybe with a fifo?


Try this:

screen -r session1 -X colon "logfile flush 1^M"

logfile flush 1 isn't actually a screen command, but colon is. The next thing you pass is the argument to it which has to be quoted and the ^M at the end should actually be a Ctrl-M. Ctrl-V followed by Ctrl-M will generally do the trick for entering an actual Ctrl-M.

  • Thank you very much. Also, I was having problems with Ctrl-V Ctrl-M: it did print ^M in the command line, but then simply printed ^M in the screen window. Might have been the quotes. I ended up using this: screen ... -X stuff "$(printf '%b' 'this into input\015')". – Gipsy King Oct 19 '10 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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