Friday, April 29, 2011

Redmon redirect to a .NET Windows.Forms application

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?

From stackoverflow
  • 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.

    Biri : Can I use Console.In also from a Windows.Forms application? I try that.
    Marc Gravell : There is very little difference, in reality, between a winform and console application... so yes, you should still be able to read from stdin.
    Biri : Thanks. I was looking for reading from stdin in winforms but haven't found anything. This is the reason. :-)

0 comments:

Post a Comment