Redmon redirect to a .NET Windows.Forms application

前提是你 提交于 2020-01-05 04:59:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!