I would like to know how to execute a command inside a screen session. i searched and I found this:
screen -S nameofscreen -X stuff "command"
When I type this, the command is typed inside the screen but it is not executed. So my queston is how to press enter using this command.
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.
在bash中,您可以在$'...'
结构中使用\\n
:
screen -S nameofscreen -X stuff $'command\n'
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 "
.
It took me some time, but what I found is: Version of screen 4.06 has a bug. If you want to send a command over a shared screen session like this, it fails:
screen -S shared_session_name -X stuff "command \n"
Screen fails with an error:
Cannot opendir /run/screen/S-$USER: Permissions denied
After update to the version screen 4.09 it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.