G
Guest
Hi Guys,
I am trying to caputre the output for an external application. The idea is
to use the System.Diagnostics.Process to run the exe in a process and
redirect the output to a string.
When I run the external command it works fine. But when i wrap it in a .net
exe it fails to exit and the application does not exit. If I kill the
external exe from task manager, the .net wrap completes.
If I proc.StartInfo.UseShellExecute to true, i can get the external
application to run, but then i lose the output.
Here is a snippet of the code.
static void Main(string[] args)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName=@"C:\Program.exe";
proc.StartInfo.Arguments="";
proc.Start();
proc.WaitForExit();
string stdoutput = proc.StandardOutput.ReadToEnd();
string stderror = proc.StandardError.ReadToEnd();
Console.WriteLine (stdoutput);
Console.WriteLine (stderror);
}
Cheers
Craig.
I am trying to caputre the output for an external application. The idea is
to use the System.Diagnostics.Process to run the exe in a process and
redirect the output to a string.
When I run the external command it works fine. But when i wrap it in a .net
exe it fails to exit and the application does not exit. If I kill the
external exe from task manager, the .net wrap completes.
If I proc.StartInfo.UseShellExecute to true, i can get the external
application to run, but then i lose the output.
Here is a snippet of the code.
static void Main(string[] args)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName=@"C:\Program.exe";
proc.StartInfo.Arguments="";
proc.Start();
proc.WaitForExit();
string stdoutput = proc.StandardOutput.ReadToEnd();
string stderror = proc.StandardError.ReadToEnd();
Console.WriteLine (stdoutput);
Console.WriteLine (stderror);
}
Cheers
Craig.