/// <summary> /// Executes a command line operation and returns <c>true</c> if there was no standard error reported. /// </summary> /// <param name="fileName">Command line file name to execute.</param> /// <param name="arguments">Command line arguments to use, if any.</param> /// <param name="standardOutput">Any standard output reported by the command line operation.</param> /// <param name="standardError">Any standard error reported by the command line operation.</param> /// <param name="processCompleted">Flag that determines if process completed or timed-out. This is only relevant if <paramref name="timeout"/> is not -1.</param> /// <param name="exitCode">Exit code of the process, assuming process successfully completed.</param> /// <param name="timeout">Timeout, in milliseconds, to wait for command line operation to complete. Set to <see cref="Timeout.Infinite"/>, i.e., -1, for infinite wait.</param> /// <returns><c>true</c> if there was no standard error reported; otherwise, <c>false</c>.</returns> public static bool Execute(string fileName, string?arguments, out string standardOutput, out string standardError, out bool processCompleted, out int exitCode, int timeout) { using CommandProcess process = new CommandProcess(fileName, arguments ?? ""); processCompleted = process.Execute(timeout); standardOutput = process.StandardOutput; standardError = process.StandardError; exitCode = process.ExitCode; return(string.IsNullOrWhiteSpace(standardError)); }
/// <summary> /// Executes a command line operation and returns <c>true</c> if there was no standard error reported. /// </summary> /// <param name="fileName">Command line file name to execute.</param> /// <param name="arguments">Command line arguments to use, if any.</param> /// <param name="standardOutput">Any standard output reported by the command line operation.</param> /// <param name="standardError">Any standard error reported by the command line operation.</param> /// <param name="processCompleted">Flag that determines if process completed or timed-out. This is only relevant if <paramref name="timeout"/> is not -1.</param> /// <param name="exitCode">Exit code of the process, assuming process successfully completed.</param> /// <param name="timeout">Timeout, in milliseconds, to wait for command line operation to complete. Set to <see cref="Timeout.Infinite"/>, i.e., -1, for infinite wait.</param> /// <returns><c>true</c> if there was no standard error reported; otherwise, <c>false</c>.</returns> public static bool Execute(string fileName, string arguments, out string standardOutput, out string standardError, out bool processCompleted, out int exitCode, int timeout) { using (CommandProcess process = new CommandProcess(fileName, arguments ?? "")) { processCompleted = process.Execute(timeout); standardOutput = process.StandardOutput; standardError = process.StandardError; exitCode = process.ExitCode; } return string.IsNullOrWhiteSpace(standardError); }