How do I call Perl script in C# application?

后端 未结 2 1943
傲寒
傲寒 2020-12-24 09:45

I want to capture output of a Perl program and display output data (string on screen) in a text box on C# Windows Form.

Here is my main C# code:

pu         


        
相关标签:
2条回答
  • 2020-12-24 10:19

    First you have to update the event handler

        void myProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)    
        {        
             if (txtOutput.InvokeRequired)        
             {            
                   UpdateUIDelegate updateDelegate = new UpdateUIDelegate 
    
                     (UpdateUI);this.Invoke(updateDelegate, e.Data);        
              }
              else UpdateUI(e.Data);
    
         }
    

    and add this line in your btnRun_Click

    proc.WaitForExit();
    
    0 讨论(0)
  • 2020-12-24 10:39

    You're going to need to use multiple threads so it doesn't interupt your UI. I have a fairly large utility class that launches processes on its own thread and pipes to delegated events.

    Sorry, I'd give an example but I'm actually in a huge rush. But one thing else you will want to watch out for with using Perl scripts is that they do not auto flush the output nicely. You need to put:

    local $| = 1;
    

    At the top of your script that you're running so it auto flushes.

    0 讨论(0)
提交回复
热议问题