1

I have a C# application which calls a exe file. Below the code I used for calling the process:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "ContasillabeGame";
proc.StartInfo.Arguments = numeroSillabe + " " + numeroToken;
proc.OutputDataReceived += new DataReceivedEventHandler(OutputToTextArea);
proc.Start();
// Start the asynchronous read of the sort output stream.
proc.WaitForExit();

And here the method used for getting data retrieved from the process.

private void OutputToTextArea(object sendingProcess, DataReceivedEventArgs outLine)
{
    // Collect the sort command output. 
    if (!String.IsNullOrEmpty(outLine.Data))
    {
        System.Console.WriteLine(outLine.Data);
    }
}

With this code i launch app ContasillabeGame but i don't have any result from that app. Why? For send message from ContasillabeGame i use this code

Sample code for send message:

System.Console.WriteLine("pippo");
John Saunders
  • 160,644
  • 26
  • 247
  • 397
bircastri
  • 153
  • 4
  • 13
  • You've set `EnableRaisingEvents` to false, and then are surprised when events are never raised. That shouldn't be a surprise. – Servy Dec 18 '13 at 15:06
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 18 '13 at 15:10

1 Answers1

0

You shoud set proc.StartInfo.RedirectStandardOutput to true before starting the process, and call proc.BeginOutputReadLine(); after calling Start().

Mauro Cerutti
  • 684
  • 4
  • 9