Re: Screen staying alive after ctrl+c-ing its initial task

Andrey Utkin <[email protected]>
Newsgroups gmane.comp.gnu.screen.user
Message-ID <CANZNk81gzezLHMFWSa6iN10fR6=xccDtSrxXNhtGgetJ4QOHEw@mail.gmail.com>
2013/2/12 Philipp Haselwarter <philipp-LuGpyVTM/[email protected]>:
> Here's a little script that does what you want.
>
> There are two issues with "screen -d -m ":
> - it double-forks, so the created session's pid can't be
>   captured
> - it might exit before the new session is ready
>
> Therefore I had to resort to forking with -D and polling.
>
>
> --8<---------------cut here---------------start------------->8---
> #!/bin/sh
> # args: $1 : session-name, $2 : shell command to run
> session=$1
> screen -c /dev/null -S $session -D -m &
> session="${!}".$session
> until screen -c /dev/null -S $session -X echo ''; do sleep 0.1; done
> screen -c /dev/null -S $session -X stuff "$2\015"
> --8<---------------cut here---------------end--------------->8---

Thanks for reply, your post is very interesting.
But proposed code does not work correctly for me:
i try this in shell:
screen -c /dev/null -S test -D -m bash -i & until screen -c /dev/null
-S test -X echo '' &>/dev/null; do echo .; sleep 0.1; done; screen -c
/dev/null -S test -X stuff 'sleep 10\015'

'sleep 10' command seems to be not executed (not seen in ps axf)
doing further 'screen -r test' gives me unusable shell.

-- 
Andrey Utkin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.