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
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();
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.