8

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!

4

2 回答 2

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

解释:

  • -d -m以分离模式启动屏幕(创建会话但不附加到它)
  • sh -c commandline启动一个执行给定命令行的 shell(因为您使用的是while内置命令,所以这是必需的)。
于 2010-01-05T16:35:40.813 回答
3

screen -h,这些看起来很有用:

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

我自己没有这样做,但这就是我要开始的地方。

更新:

帮助的顶部还说

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

所以-X开关可能是执行屏幕命令而不是shell命令。您也许可以在-dmS <name>没有任何-X开关的情况下将您的命令放在后面。

于 2010-01-05T16:27:25.250 回答