1

I need to execute a script locally. The problem is, it needs to use screen and send the ctrl d command.

How would i do this? The script will be on my local windows machine. i can use winscp, putty, mingw and other apps.

3 Answers3

1

You can use expect (expect home page, included in most unix software distributions) to script interactions with programs that run in text terminals.

However, there's probably a simpler way of doing what you're trying to do. You can send commands to a screen session from any command line, and you can use screen's stuff command to insert input into a screen window. See Why is screen seemingly doing nothing with commands passed with -X?, Sending input to a screen session from outside for examples.

screen -S sessionname -p windowname -X stuff $'\004'

If this answer isn't helping you, give more information about what you're trying to do.

1

From screen(1) manual

   -d|-D [pid.tty.host]
        does not start screen, but detaches the elsewhere running screen
        session. It has  the same  effect  as typing "C-a d" from screen’s
        controlling terminal. -D is the equivalent to the power detach key.
        If no session can be detached, this option is ignored. In combination
        with the -r/-R option more powerful effects can be achieved:

I usually use screen -AmdS sessionname commandline to run a commandline in a screen session and immediately detach. e.g. running a screen from a cronjob

@reboot /usr/bin/screen -AmdS shoutcast /home/foo/sc_serv /home/foo/sc_serv.conf

Adding new commands on an existing detached screen and detach immediately.

screen -dr sessionname -X commandline
forcefsck
  • 7,964
0

Your arrangement doesn't make any sense to me. Are you asking how to send keys to screen from something outside screen? You might use expect for that senario. You can also launch screen with a custom config file to change the ctrl-d to something easier to send.

Caleb
  • 70,105