Following scenario:
I have a Console Application with following code:
static void Main(string[] args)
{
// Some code.
Console.WriteLine("Done");
Console.ReadLine();
}
The application is successfully built and "Test.exe" is generated.
Now I have another Console application which executes the generated exe.
static void Main(string[] args)
{
var processStartInfo = new ProcessStartInfo("Test.exe")
{
UseShellExecute = false,
RedirectStandardOutput = true
};
// Setup the process
process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
process.OutputDataReceived += ProcessOnOutputDataReceived;
process.Start();
process.BeginOutputReadLine();
// Detect here if application is completed.
}
Console.ReadLine();
}
private static void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
{
Console.WriteLine(dataReceivedEventArgs.Data);
}
When I execute the above code, it calls the "Test.exe" and output of "Test.exe" is displayed in the console window of current process.
"Test.exe" waits for input at "Console.ReadLine()" and the current process waits for "Test.exe" to finish.
Is it possible to detect if "Test.exe" is waiting for an input in current process?