C# Redirecting Standard Input/Error
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 t开发者_JAVA技巧ake 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.
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:
- If you know the possible messages, parse them to find out whether it's a response or an unrelated message.
- If you can change the Java application, change it so that it uses some better protocol for communication.
精彩评论