C# 重定向标准输入/错误
我的应用程序用于启动 Java 进程并管理它(如果崩溃则重新启动它,提供 TCP 服务器来发出远程命令等)。使用我的 RCON 服务器(远程控制台),它工作正常。但是,当我将命令发送到 Java 进程时,我想获取回复(Java 进程实际上以 StandardError 而非 StandardOutput 进行回复)并将该响应显示给远程连接的人员。
我的问题是,由于他们的输入是通过我的 RedirectedStandardInput 函数发送的,我如何确保从 RedirectedStandardOutput 获得正确的回复?
最好的选择是拥有某种全局标志,这意味着“RCON 命令已发送,通过标准错误收到的下一条消息应用于回复”?我想我主要担心的是,由于 Java 进程是一个游戏,使用这种方法,它可能会拾取诸如“玩家已加入游戏”之类的内容,而不是对命令的实际响应。对命令的响应在视觉上是即时的,但我不知道它是否是或只是有一个小的延迟。
My application is used to Launch a Java process and manage it (restart it if it crashes, provide a tcp server to issue remote commands, etc). With my RCON server (remote console) it works fine. However, when I send the command to the Java process, I would like to take the reply (the Java process actually replies in StandardError instead of StandardOutput) and show that response back to the person remotely connected.
My problem is since their input is sent through my RedirectedStandardInput function, how can I make sure I get the right reply from RedirectedStandardOutput?
Would the best bet be to have some sort of global flag that means "RCON command was sent, next message received through Standard Error should be used for reply"? I guess my main concern is that with the Java process being a game, using this method, it might pickup something like "Player has joined the game" instead of what the response to the command actually is. The response to a command is visually instant, but I don't know if it is or just has a small delay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于Java应用程序是如何实现的。但如果我们对此一无所知,我们就必须假设它可以是多线程的。但这意味着在您发送命令和响应之间可能会出现不是对命令的响应的消息。
如果是这种情况,您有多种解决方案:
This depends on how the Java application is implemented. But if we don't know anything about it, we have to assume it can be multi-threaded. But that means that messages that aren't responses to your commands can appear between you send the command and the response.
If that's the case, you have several solutions: