Execute a command and get the result in a winform
Source : http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = “YOURBATCHFILE.bat”;
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.