Skip to content

Instantly share code, notes, and snippets.

@julesx
Created July 18, 2018 14:36
Show Gist options
  • Save julesx/5d85cb0ff03a2c47ca90b6d1b7117ec8 to your computer and use it in GitHub Desktop.
Save julesx/5d85cb0ff03a2c47ca90b6d1b7117ec8 to your computer and use it in GitHub Desktop.
public static void ExecuteCommand(String checkOutFile)
{
int ExitCode;
ProcessStartInfo ProcessInfo;
Process process;
ProcessInfo = new ProcessStartInfo(checkOutFile);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
ProcessInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(checkOutFile);
// *** Redirect the output ***
ProcessInfo.RedirectStandardError = true;
ProcessInfo.RedirectStandardOutput = true;
process = Process.Start(ProcessInfo);
process.WaitForExit();
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
ExitCode = process.ExitCode;
Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
Console.WriteLine("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");
process.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment