大网数据广告活动
服务器运维问答

Invoke remote program with socat and wait for it to complete

· 52CE 我爱测

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 s…

问题原文

原帖链接 · koehn · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · koehn · CC BY-SA 4.0

OK, I think I have it: put -t 10 on both client and server, and they'll both wait 10 seconds after EOF from the client before closing both sockets.

Protip: use lots of -d to get a view into what socat is doing behind the scenes, and create a simple local test case you can easily reproduce.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。