I need to invoke a program x
on server foo from client bar. Program x
takes some time to load, then reads input from stdin and transmits output to stdout before terminating. I've been trying to use socat
to accomplish this.
On server foo I setup the following:
socat -lmlocal2 TCP-LISTEN:4444,fork,reuseaddr,linger=6 SYSTEM:x
And to invoke the command I run this on client bar:
echo "someinput" | socat - TCP:foo:4444
When I run the client with -v I can see socat
is transmitting the data to foo, and if I run top
on foo I can see it invoking x
(which takes awhile to start up), but the client on bar doesn't wait around for x
to finish, and socat
on server foo reports an I/O error.
If I change the SYSTEM
command on foo to "SYSTEM:sleep 5; cat > /tmp/test ; echo 'done'"
, it does correctly read however much input I send it and puts it into /tmp/test
. The input is all transmitted over the network and fed to x
, it's just the output of x
that is lost.
How do I get the socat
client to stay open until x
finishes writing to stdout and closes it? I tried adding linger=6
to the server but that hasn't helped.