View previous topic :: View next topic |
Author |
Message |
alex.blackbit Advocate
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Wed Mar 18, 2009 4:54 pm Post subject: sending commands to screen sessions |
|
|
hi,
i want to send a command to a screen session.
so i create a detached session with screen -d -m -S asdf. (actually the effect would be the same if started normally and then detached).
now i want to send a simple command to that screen session with screen -d -r asdf -X touch asdf.
unfortunately nothing happens. the file is not touched. when i re-attach the session, there is no output. i do not get any error messages.
who knows what i do wrong?
thanks in advance for the help. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Wed Mar 18, 2009 7:08 pm Post subject: |
|
|
in
screen -S asdf -X touch test
"touch" is supposed to be a screen command, which is not, you should see a warning, but it has disapeared once you re-connect to the screen session, you can have it back by pressing ^A m, (default binding for the lastmsg screen command)
try Code: | screen -S asdf -X stuff $'echo working\n' |
or Code: | screen -S asdf -X stuff "echo working^M" | where ^M is 'obtained(?)' with ^V^M (ctrl-V ctrl-M or ctrl-V then ENTER) _________________ The End of the Internet! |
|
Back to top |
|
|
alex.blackbit Advocate
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Wed Mar 18, 2009 7:30 pm Post subject: |
|
|
thanks for your answer, unfortunately i am not sure if i understand what you are trying to tell me.
here is what i did Code: | ahuemer@seaburg ~ % screen -d -m -S asdf
ahuemer@seaburg ~ % screen -S asdf -X touch foo "echo working^M"
ahuemer@seaburg ~ % ls -l foo
ls: cannot access foo: No such file or directory
ahuemer@seaburg ~ % |
when i am inside the screen session, ^a m does nothing.
please describe more precisely what you mean. thanks. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Wed Mar 18, 2009 9:08 pm Post subject: |
|
|
the -X takes a screen command as parameter.
screen commands are commands listed in the manual (the screen command itself, select, focus, detach...)
You're trying to send 'some text' to the preselected window.
To achieve that you'll use the 'stuff' screen command (check the manual):
Code: | screen -S asdf -X stuff "some text" |
In that window you happen to have a shell running (default behaviour when starting screen or creating a new window without any parameter), so "some text" can very well be a shell command:
Code: | screen -S asdf -X stuff "touch foo" |
if you try this, you'll notice that the file foo is *not* touched, if you re-attach to the screen, you'll see that the command do appear at the prompt, but is not executed, you need to type ENTER manually or to also send the newline character with the command:
for the later, you can use the shell quoting feature to send that character
Code: | screen -S asdf -X stuff $'touch foo\n' |
As for the ^A m not working, are you aware that ^A is just a shorter way to say ctrl-A (with ctrl-A being the default screen escape character, I don't think you have change the default setting, haven't you?) _________________ The End of the Internet!
Last edited by truc on Thu Mar 19, 2009 8:27 am; edited 1 time in total |
|
Back to top |
|
|
alex.blackbit Advocate
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Wed Mar 18, 2009 10:34 pm Post subject: |
|
|
thanks for the explanation, truc.
the single day you are longer part of the gentoo community seems to make the difference!
in my situation (a detached terminal) i have to use Code: | screen -r -S asdf -X stuff $'touch foo\n' |
that way i get what i wanted. i did not notice that -X awaits a screen command. i thought it was a shell command.
i understood what you meant with ^A m. but that still does nothing.
thanks again. |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Thu Mar 19, 2009 8:38 am Post subject: |
|
|
alex.blackbit wrote: | the single day you are longer part of the gentoo community seems to make the difference! | And now, a day later, you know what you were missing just yesterday
Quote: | in my situation (a detached terminal) i have to use Code: | screen -r -S asdf -X stuff $'touch foo\n' |
| Are you sure you need the -r ?
Quote: | i understood what you meant with ^A m. but that still does nothing. | I just tried, and you're right, there is no error thrown if the screen is detached, you can still see the error, if the screen is attached
You're very welcome, I could talk about screen for hours _________________ The End of the Internet! |
|
Back to top |
|
|
|