问题
I have an interesting task: to write a program which captures input from the program called Redmon. It is basically a virtual printer which redirects the output to a program.
I installed Redmon and created a winforms application to catch the output. But I'm stuck here. I checked what does my program receives and it is nothing on the parameter level (the string[] on main args are empty).
Redmon starts my program, but then it is stopping. I guess I should read somehow the content it is sending to the program, but how?
回答1:
I would assume that Redmon streams to stdin - in which case you'll have to read from the input stream - either via Console.In (if it is character-based), or Console.OpenStandardInput (for raw binary stream access).
As a trivial example of something that reads from stdin (it reads text lines, reversing each):
static void Main() {
WriteReversedLines(Console.In);
}
static void WriteReversedLines(TextReader reader) {
string line;
while ((line = reader.ReadLine()) != null) {
char[] chars = line.ToCharArray();
Array.Reverse(chars);
Console.WriteLine(chars);
}
}
Obviously you need to treat binary data slightly differently, but conceptually it is similar.
来源:https://stackoverflow.com/questions/751182/redmon-redirect-to-a-net-windows-forms-application