Pretty new to C# (and I would describe myself as a beginner in programming, but I'm ambitious), so this is probably something very simple to solve.
I have a function getting called in a switch like this:
case "PERL_TEST":
FileInfo fi = new FileInfo("hello.txt");
mainproc.process_file(fi);
MessageBox.Show(perl_o);
break;
The mainproc.process is a function that calls Perl like this:
myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("perl.exe");
myProcessStartInfo.Arguments = "perly.pl";
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcessStartInfo.CreateNoWindow = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.OutputDataReceived += new DataReceivedEventHandler(Perl_Output);
myProcess.Start();
myProcess.BeginOutputReadLine();
The Perl_Output function contains nothing in it, but receives the args: object o, and DataReceivedEventArgs e.
What method would be best to return e.Data to be shown in the messagebox from the original switch (perl_o)? I'm not sure how to do this. I'm not even sure if I have the most efficient method for calling perl externally. The whole application is based on perl being called externally, and returning the data. The part that calls perl is already running on a second thread. Any and all help would be appreciated as I am a beginner... be gentle :)
Edit: e.Data is not declared. It is passed when the event Perl_Output is called. The switch is for basic network commands, in this case: "PERL_TEST".
perl_o is not declared. I'm looking for a way to make perl_o = e.Data AFTER mainproc.process_file finishes it's process.
The best overall way for me would be if I could declare the function containing myProcess as string (instead of void), have the function wait for the process to finish running, then return the output of the process.