启动屏幕(unix 命令)+在 1 个命令中运行一个命令?

发布于 2024-08-16 11:09:46 字数 319 浏览 2 评论 0原文

想知道如何启动一个命令,例如:

while :; do ./myCommand; done;

但我不想执行通常的“

screen -S nameOfMyScreen

然后命令

while :; do ./myCommand; done;

然后分离屏幕”,

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

我希望它启动并分离。谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故笙诉离歌 2024-08-23 11:09:46
screen -d -m sh -c "while :; do ./myCommand; done;"

说明:

  • -d -m 以分离模式启动屏幕(创建会话但不附加到它)
  • sh -c commandline 启动一个执行给定命令行的 shell (必要的,因为您使用的是 while 内置函数)。
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).
苍白女子 2024-08-23 11:09:46

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 之后,而无需任何 -X 开关。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文