Created
July 18, 2018 14:36
-
-
Save julesx/5d85cb0ff03a2c47ca90b6d1b7117ec8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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