Wednesday, March 13, 2013

Execute an .exe and get the output returned by an .exe

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "C:\\MyExe.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = false;
myProcess.StartInfo.RedirectStandardInput = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.Start();

StreamReader sOut = myProcess.StandardOutput;
StreamReader sErr = myProcess.StandardError;

myProcess.WaitForExit();
string output = sOut.ReadToEnd();

textBox1.Text = output;

No comments:

Post a Comment