Screen: Start/stop detached session via one command

From FVue
Jump to: navigation, search

Problem

I want to start and stop detached screen sessions via one command, e.g. to start/stop info bash within screen:

   # Start `info bash' within detached screen
screen -S info -d -m info bash
   # Stop `info bash' screen
screen -S info -X stuff q

But screen doesn't stop?

Solution

Use `-p 0' option to send the -X command to the specified window. There is a known problem that "A screen session started in detached mode cannot accept any 'stuff' commands unless the the session is first attached, and then re-detached." [1]

   # Start detached screen session `info bash'
screen -S info -d -m info bash
   # Stop screen session `info bash' by sending key `q'
screen -S info -p 0 -X stuff q
   # Alternative: Stop screen session `info bash' by sending key `CTRL-C'
screen -S info -p 0 -X stuff ^C       # Enter literal `^C' in bash by pressing CTRL-V followed by CTRL-C
screen -S info -p 0 -X stuff $'\003'  # $'\003' is octal notation for CTRL-C
screen -S info -p 0 -X stuff $'\cC'   # $'\cx' is bash notation for a control-x character

Journal

20070819

Nabble - screen -X stuff
Forum thread stating known problem "A screen session started in detached mode cannot accept any 'stuff' commands unless the the session is first attached, and then re-detached."

Comments

blog comments powered by Disqus