csteifel
csteifel

Reputation: 2934

Reading/writing to screen process in C/C++

I was wondering how one might connect to a screen process in C/C++, I often want to have a C program listen to the output to that screen window and react to that output as well as send some input to the program running on that session. I am just unsure as to how I'm supposed to connect to that screen session and I haven't found anything very useful doing my searches.

Upvotes: 4

Views: 740

Answers (1)

Andy Ross
Andy Ross

Reputation: 12043

Doing exactly what you want is involved. screen expects to be running inside a terminal device, so if (I'm assuming you are on linux) you want to create it programatically you have to set up a terminal pseudodevice using posix_openpt(), set up the slave device with grantpt()/unlockpt(), forking, opening the slave pty in the child process, duping it to stdin/out/err, and finally exec'ing screen with the appropriate options. Now you can send commmands and receive terminal notifications as if you were a terminal emulator. Check the man page for pty(7) for more details; I'm quite sure I've missed some.

Which is all a huge mess, and almost certainly overcomplicated for what you are trying to do. So: what are you actually trying to do?

Upvotes: 1

Related Questions