How to start a new process in a new window in an existing GNU screen session, from outside the session

我们两清 提交于 2019-12-18 05:09:12

问题


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

How to start a process from another application and then open a terminal to that process in gnu screen

...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

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


回答1:


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

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\n' in the new window:

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

The man pages of course have much more detail.



来源:https://stackoverflow.com/questions/1236376/how-to-start-a-new-process-in-a-new-window-in-an-existing-gnu-screen-session-fr

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