I have two console application, the first is "Process1", which compiled as a exe and cannot change the code inside it. The second is a "meter" console app used to calc the launch time of the Process1. I want to now the time of the moment when the HelloWorld is printed in the Console windows.
// {My Process1}: //I compiled it into a assembly called process1.exe.
Class Process1{
static void Main(String[] args]){
Console.Write("Hello word");
}
}
My 2nd application is an console application which call process1.exe as a Process, I want to know when the process1 is "ready", assume its the time when the "Hello Word" is printed. I read about Process.OutputDataReceived event, but the event is never fired when debugged, the code inside never printed.
// {Meter Application}
public Class Student{
String ID;
String Name;
}
public Class Program{
public static void Main(String[] args){
p.StartInfo = new ProcessStartInfo("process1.exe")
{
UseShellExecute = false,
//Add this line
RedirectStandardOutput = true,
};
Student st = new Student();
p.OutputDataReceived += P_OutputDataReceived;
p.Start();
//Add this line
p.BeginOutputReadLine();
p.WaitForExit();
}
private static void P_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
string output = e.Data;
Console.WriteLine("Process1 ready at: "+DateTime.Now);
Console.WriteLine("Data is: " + output);
}
}