How to execute a command inside a screen session

ぃ、小莉子 提交于 2019-12-03 08:50:56

In the bash shell you can use ctrl-V to explicitly put non-printable characters into a string. So try ctrl-V ctrl-L ctrl-V ctrl-M at the end of your command just before the ".

In bash, you can use \n in the $'...' construct:

screen -S nameofscreen -X stuff $'command\n'

I'd do something like this:

screen -S sessionName bash -c 'cmd; exec bash'

it starts a new session executes cmd and launches shell (otherwise it'd drop that new session).

-X will allow you to send input to a specified session -- that's why your command didn't execute. To execute it you'd need to add enter sign like Paul suggested. It can be done with Ctrl+v and then Enter. That will produce that ^M. So:

screen -S sessionName -X stuff 'cmd^M'

That, in itself, won't however attach a detached session.

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