Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am looking to use screen to easily access a running program from my perl script, and am interested in using this function listed in the man pages:
Quote:
-X Send the specified command to a running screen session. You can
use the -d or -r option to tell screen to look only for attached
or detached screen sessions. Note that this command doesnât work
if the session is password protected.
I want to send the screen session a command but I am very confused on how to go about using this -X switch. Please help.
You may be confusing the different acts of sending commands to 'screen' itself, vs. sending commands to the program(s) running in a screen window. It sounds like you want the latter.
You still use the -X option, but accompanied by the 'stuff' command.
An example that might stop a running application...
Code:
screen -X stuff 'exit'
The 'stuff' command is sent to screen, and the argument(s) to the stuff command are entered into the screen window, as if typed at the keyboard. You can embed commands such as this into your perl scripts using the perl 'system()' command.
That seems to be getting the command to the screen, but it doesn't enter it (Like the user pressing the enter button. Any idea how to get it to simulate an enter key after the command. Also, how do I specify exactly which screen to send it to?
Usually the enter key sends something like '\r' or '\n' (using perl syntax). That should be part of the string that is 'stuffed'. You specify the screen session with the -S option.
If you are trying to send the newline from a shell commandline, it is different than from a literal string embedded into perl code.
To send a CR in a bash script, try
Thanks! It worked out nicely, just enclosed the above command using backticks, and I'll make the -S name a perl variable. Is there anyway to get it so that screen does not place the PID on the session name?
I think it is always there as part of screen's full name, however I beleive if you open the session with a name, you can reconnect to it by giving that unambiguous name as an identifier. I think...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.