I'm writing a collection of scripts to talk to an external program. My problem is that the scripts are only "alive" for a short time (triggered by a keypress in a larger program) but the external program needs to stay running between calls, and was originally designed for interactive use (think debugger).
If I just wanted to write a single script to run the program, I'd open a PTY to it and send/receive data on that. This works (my scripts are in LUA and lpty can deal with the PTY) but it can't keep the program running when the script terminates.
If the external program offered me a socket to connect on (like gdb does), I could just save the name somewhere and have each script connect to that socket. But it was only meant to be used interactively.
I could write a daemon that starts the external program, opens a PTY to it and then listens on a socket itself. The scripts could then connect to the daemon's socket and send data, which the daemon would forward to the program over the PTY and send the results back.
The format of the data I'm exchanging with the external program is line-based, but I don't know in advance how many lines I'm going to get back from a single command. Not a problem with a PTY, but a bit more work with
I'm wondering if there isn't a better way to do this. Can I somehow open a PTY to a program and get its "address", from which I can later connect and disconnect multiple times from my scripts? (Only one script can ever run at a time so concurrency is not a problem.) That would avoid using sockets at all.
Or is there some combination of options in
socat that does exactly this already?