Call a third party console application and return the result

  • Thread starter Thread starter GD
  • Start date Start date
G

GD

I am trying to execute a third party console application and return the
result dispalayed in the console screen.

Can this be achieved?

Thanks.

GD
 
GD,

Yes, using the Process class, you can start the new application easily.

When creating the ProcessStartInfo instance to pass to the Start method,
make sure that UseShellExecute is set to false, and that
RedirectStandardError, RedirectStandardInput, and/or RedirectStandardOutput
properties to allow you to look at the appropriate input/output.

Once you set those properties, you can then access the StandardError,
StandardInput and StandardOutput properties on the Process instance that you
start and process the input/output as you wish.
 
Nicholas,

Thank you very much for your solution. It works like a charm.

For those who are interested in same solution, I post my test code here:
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo();

psi.FileName = "ConsoleTest.exe";

psi.UseShellExecute = false;

psi.RedirectStandardOutput = true;

System.Diagnostics.Process p = new System.Diagnostics.Process();

p.StartInfo = psi;

p.Start();

txtConsoleOutput.Text = p.StandardOutput.ReadToEnd();

p.WaitForExit();

GD


Nicholas Paldino said:
GD,

Yes, using the Process class, you can start the new application easily.

When creating the ProcessStartInfo instance to pass to the Start
method, make sure that UseShellExecute is set to false, and that
RedirectStandardError, RedirectStandardInput, and/or
RedirectStandardOutput properties to allow you to look at the appropriate
input/output.

Once you set those properties, you can then access the StandardError,
StandardInput and StandardOutput properties on the Process instance that
you start and process the input/output as you wish.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

GD said:
I am trying to execute a third party console application and return the
result dispalayed in the console screen.

Can this be achieved?

Thanks.

GD
 
Back
Top