我想知道如何启动类似以下命令的操作:
while :; do ./myCommand; done;
但是,与其按照惯例做法
screen -S nameOfMyScreen
然后执行该命令。
while :; do ./myCommand; done;
然后将屏幕分离。
^a ^d (Control "a" the control "d"
我希望它能够启动并分离。谢谢!
我想知道如何启动类似以下命令的操作:
while :; do ./myCommand; done;
但是,与其按照惯例做法
screen -S nameOfMyScreen
while :; do ./myCommand; done;
^a ^d (Control "a" the control "d"
我希望它能够启动并分离。谢谢!
screen -d -m sh -c "while :; do ./myCommand; done;"
解释:
-d -m
以分离模式(创建会话但不连接)启动 screen。sh -c commandline
启动一个 shell,该 shell 执行给定的命令行(由于使用了 while 内置命令,因此这是必要的)。从 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
开关可能是执行screen命令而不是shell命令。您可以在-dmS <name>
之后直接放置您的命令,而无需任何-X
开关。
bash -c
或类似的东西。 - Noufal Ibrahim
-c
参数并不是传递给screen
命令,而是传递给sh
。当screen
命令行解析器读取到sh
(即没有短横线的内容)时,它知道后面没有更多的选项,剩下的所有内容都是要执行的命令。 - Heinziscreen
而不是我的命令中获取输出。我尝试添加引号,但没有成功。使用这里建议的子 shell 很棒!\o/ - msb