If you have an application which calls another process in a command window and that process has updating stats that output to the console window. That mean you have to inject another console program to your console program!
How do you can do it?
- In C# language, we have one API which is Process API. we can use it to call the process and mount into your console programSource Code
static void Main(string[] args)
{
// get your exeFileName;
string exeFileName = Path.Combine(Path.GetTempPath(), "abc.exe");
Process process = new Process();
process.StartInfo.FileName = exeFileName;
process.StartInfo.Arguments = args[0] + " " + args[1];
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += Process_OutputDataReceived;
process.ErrorDataReceived += Process_ErrorDataReceived;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
private static void Process_ErrorDataReceived(object sender,
DataReceivedEventArgs e)
{
Console.WriteLine(e.Data); // write to ourself console program
}
private static void Process_OutputDataReceived(object sender,
DataReceivedEventArgs e)
{
Console.WriteLine(e.Data); // write to ourself console program
}
If you have any questions, leave your comment and we can discuss about it!
Zidane
0 comments:
Post a Comment