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");
2
  • You've set EnableRaisingEvents to false, and then are surprised when events are never raised. That shouldn't be a surprise. Commented Dec 18, 2013 at 15:06
  • I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". Commented Dec 18, 2013 at 15:10

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.