i would like to execute an executable file with some parameters.
I would like my WPF application to output the console lines and show it in a textblock asynchronously.
This is what i’ve done so far:
System.Threading.Thread.Sleep(5000);
System.Diagnostics.Process runantc = new System.Diagnostics.Process();
runantc.StartInfo.FileName = "CMD.EXE";
runantc.StartInfo.Arguments = "/C " + Antcbatchpath;
runantc.StartInfo.UseShellExecute = false;
runantc.StartInfo.RedirectStandardOutput = true;
runantc.StartInfo.RedirectStandardError = true;
runantc.OutputDataReceived +=new DataReceivedEventHandler(runantc_OutputDataReceived);
runantc.Start();
runantc.BeginOutputReadLine();
runantc.Close();
private static void runantc_OutputDataReceived (object sendingProcess,
DataReceivedEventArgs outLine)
{
//i am not sure what should be here
}
The above code is altered according to msdn’s webpage
I have a lot of trouble following their code namely because they need to add in strings or some sort. I am a beginner at events handling and such processes. Please kindly help me, all i need is just to output these lines to a textblock asynchronously.
For example, the console would output:
running test...
i should see that in textblock:
running test...
then after a few seconds another line appears:
running test...
this is a new line 1
and the above should also appear in the textblock after a few seconds:
running test...
this is a new line 1
The following code should do what you want:
EDIT: Ok it seems I have to explain the code a little bit:
The Dispatcher.BeginInvoke function needs a delegate as callback and an array of parameters.