I’m working on a project where it’s necessary to use a client application provided by a third party to query the third party’s system from within my own system. This can be done very easily in .net by simply redirecting standard input and output.
Here is a sample application that demonstrates how:
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"WorkApp.exe";
p.Start();
string input;
do
{
// get request from user
Console.Write("> ");
input = Console.ReadLine();
p.StandardInput.WriteLine(input);
// get response from console
var output = p.StandardOutput.ReadLine();
Console.WriteLine(output);
} while (input != "x");
if (!p.HasExited)
{
p.Kill();
}