Sending ctrl-c to specific screen session

两盒软妹~` 提交于 2019-12-20 09:47:13

问题


I am designing a script to launch a process inside a named screen session.

as_user "screen -p 0 -S **$command** -X eval 'stuff \"wine LFS.exe /cfg=**$command**.cfg\"\015'"

So bash myscript.sh start test will create a screen named test and run the test.cfg with the software.

Now I want my script to access the specific screen session and do a CTRL+C to stop the running process so i can kill the screen session.

Something like this:

as_user "screen -p 0 -S **$command** **... kill the process with ctrl-c...**"
as_user "screen -p 0 -S **$command** -X eval 'stuff \"exit\"\015'"

回答1:


I don't quite understand you but to send ctrl-c to a window in a screen session:

screen -S session_name -X at window_number stuff $'\003'
# or
screen -S session_name -X -p window_number stuff $'\003'

If you want to send something to all the windows, use # (needs to be quoted) as the window_number.

UPDATE:

Screen's stuff command also supports ^X (or ^x) to mean CTRL-X so the following command can also be used to send CTRL-C.

screen -S session_name -X at window_number stuff ^C


来源:https://stackoverflow.com/questions/16001578/sending-ctrl-c-to-specific-screen-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!