如何在现有 GNU 屏幕会话的新窗口中从会话外部启动新进程 [英] How to start a new process in a new window in an existing GNU screen session, from outside the session

查看:24
本文介绍了如何在现有 GNU 屏幕会话的新窗口中从会话外部启动新进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里问了一个类似的问题,并且非常接近我正在寻找的内容

I asked a similar question here and got pretty close to what I'm looking for

如何从另一个应用程序启动一个进程,然后在 gnu 屏幕中打开该进程的终端

...但是,这并没有完全达到我所追求的目标,即在现有屏幕会话(不是新屏幕会话)中的新窗口(不是现有窗口)中启动一个进程.

...but, this doesn't quite get to what I'm after, which is starting a process in a new window (not an existing window) in an existing screen session (not a new screen session).

如果您在屏幕会话中的命令提示符下,您可以这样做:

If you are at a command prompt in a screen session, you can do this:

screen [screen options] command param1 param2

但是,如果你不在会话中,你会怎么做呢?例如,如果您想将其作为 cronjob 运行?

But, how do you do it if you are outside the session? For example, if you want to run this as a cronjob?

推荐答案

当你不在屏幕会话中时,你可以将 -X 标志传递给 screen 以执行屏幕命令.

When you aren't in a screen session, you can pass the -X flag to screen to execute a screen command.

例如,屏幕中的 screen 命令会打开一个新窗口,可选择执行命令.

For example, the screen command in screen opens a new window, optionally with a command to execute.

假设您已经在某处打开了屏幕:

Assuming you already have screen open somewhere:

screen -dr -X screen sleep 20

请注意,一旦命令(在本例中为睡眠)完成,新窗口将关闭.如果你想让它保持打开状态,你可能会做这样的事情,这将在新窗口中输入日期 ":

Note that the new window will close once the command (sleep in this case) finishes. If you want to keep it open you could potentially do something like this, which will type 'date ' in the new window:

screen -dr -X screen
screen -dr -X stuff "date
"

手册页当然有更多的细节.

The man pages of course have much more detail.

这篇关于如何在现有 GNU 屏幕会话的新窗口中从会话外部启动新进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆