1

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?

Biri
  • 7,101
  • 7
  • 38
  • 52

1 Answers1

3

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.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Can I use Console.In also from a Windows.Forms application? I try that. – Biri Apr 15 '09 at 11:23
  • There is very little difference, in reality, between a winform and console application... so yes, you should still be able to read from stdin. – Marc Gravell Apr 15 '09 at 11:26
  • Thanks. I was looking for reading from stdin in winforms but haven't found anything. This is the reason. :-) – Biri Apr 15 '09 at 11:40