使用 shell 命令将数据汇集到守护程序化的非守护程序中
这就是我想要做的:
$ serverise 通常使用 stdin stdout &
唯一 ID-221B $ clienty 221B“令人惊讶!”
初级
$ clienty 221B“我刚才说什么?”
“令人惊讶”,尽管这些方法简单易行,一旦解释过。
$ clienty 221B“那么,您在客户端的调用之间持续存在吗?”
确实如此。
我尝试过双命名管道,但它们只最后一次调用。我认为这是因为服务器端收到 EOF,因此假设 stdin 已被用户关闭。
套接字似乎是可行的方法,但大多数包装器都采用类似 http 的模型,并且每次有人连接时都会分叉出一个新程序。索猫看起来还好,但也只是一击就死了。
我见过 Gnu Screen 和 Tmux 用于此目的,但这似乎有点过分了,说实话,我不能假设用户的环境不会包含其中任何一个,因此任何像这样的解决方案在面对时都会有点脆弱其中的非标准配置。这似乎也有点矫枉过正。
这似乎是一个以前会出现的问题,所以我一定是在错误的地方寻找执行此操作的时髦小实用程序。
This is what I want to do:
$ serverise normally-barely-interactive-program-that-uses stdin stdout &
unique-id-221B
$ clienty 221B "Astonishing!"
Elementary
$ clienty 221B "what did I just say?"
'Astonishing', although the methods are simple and easily followed, once explained.
$ clienty 221B "so, you persist between invokations of the client?"
Indeed.
I have tried dual named pipes, but they only last one invocation. I think this is because the server side gets an EOF, and so assumes that stdin has been closed by the user.
Sockets seem to be the way to go, but most of the wrappers assume an http-like model, and fork off a new program each time someone connects. Socat seems okay, but it also dies after just one go.
I have seen Gnu Screen and Tmux used for this, but this seems overkill, and to be honest, I can't assume that the user's environment won't contain either, and thus any solution like this would be a bit fragile in the face of non-standard configs of those. It also seems like a bit of overkill.
This seems like a problem that would have come up before, so I must be looking in the wrong place for the snazzy little utility that does this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于命名管道仅持续一次调用的问题:如果这确实是您唯一的问题,那么它很容易解决。 (我的示例几乎没有交互程序恰好是 bc )
这是通过重新打开输入管道一次只读取一行,同时写入单个未命名管道(该管道在整个会话中仅打开一次)来实现的。
请注意:
Regarding your problem with named pipes only lasting one invocation: if that's indeed your only problem, it's an easy one to work around. (my sample barely interactive program happens to be
bc
)This works by reopening the input pipe to only read one line at a time, while writing to a single unnamed pipe that is only opened once for the whole session.
Note that:
在您描述的一般情况下这是不可能的。
您描述的东西看起来大多像查询/答复服务,但只有标准输入和标准输出,您的几乎交互式程序无法提供一种方法来了解每个答复转到哪个查询。
在您的示例中,考虑您的第一次
clienty
调用。显然,查询“Astonishing”可以直接传输到服务器的标准输入,并且服务器似乎会在其标准输出上写入“Elementary”。但那又怎样呢?包装纸应该立即转移吗?缓冲一下?它如何知道答案是否完整?假设您已经解决了这个问题,如果多个客户端同时查询,它如何知道将答案发送回哪一个?您需要最少的协议来解决这个问题。它可以像“回复是单行的、有保证的和有序的”一样简单。
This is impossible in the generic case you describe.
You describe something that looks mostly like a query/reply service, but with only stdin and stdout, your barely-interactive-program doesn't provide a way to know which query each reply goes to.
In your example, consider your first
clienty
invocation. Obviously, the query 'Astonishing' could be transfered to the server's stdin directly, and it seems like the server would write 'Elementary' on its stdout. But what then? Should the wrapper transfer it immediately? Buffer it? How does it know whether the answer is complete? Assuming you'd solved that, if multiple clients are querying at the same time, how does it know which one to send the answer back to?You need a minimum amount of protocol to solve that. It could be as simple as "replies are single-line, guaranteed and ordered."