Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

The man pages of course have much more detail.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...