Starting up a screen (unix command) + running a command in 1 command?

与世无争的帅哥 提交于 2019-12-12 08:36:41

问题


Was wondering how I can start up a command such as:

while :; do ./myCommand; done;

But instead of doing the usual

screen -S nameOfMyScreen

Then the command

while :; do ./myCommand; done;

Then detach the screen

^a ^d (Control "a" the control "d"

I would like it to start and detach. Thanks!


回答1:


screen -d -m sh -c "while :; do ./myCommand; done;"

Explanation:

  • -d -m starts screen in detached mode (create session but don't attach to it)
  • sh -c commandline starts a shell which executes the given command line (necessary, since you are using the while builtin).



回答2:


From screen -h, these look useful:

-dmS name     Start as daemon: Screen session in detached mode.
-X            Execute <cmd> as a screen command in the specified session.

I haven't done this myself, but that's where I'd start.

Update:

The top of the help also says

Use: path/to/screen [-opts] [cmd [args]]

so the -X switch may be to execute a screen command as opposed to a shell command. You might just be able to put your command after the -dmS <name> without any -X switch.



来源:https://stackoverflow.com/questions/2007351/starting-up-a-screen-unix-command-running-a-command-in-1-command

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