问题
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