private int LaunchProcess(string workingDirectory, IDictionary <string, string> additionalEnvVars, string command, string param, bool printTestOutput, bool throwIfError, List <string> output) { var processStartInfo = new ProcessStartInfo(command, param) { StandardOutputEncoding = Encoding.Default, RedirectStandardOutput = true, RedirectStandardError = false, UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = workingDirectory }; if (additionalEnvVars != null) { foreach (var entry in additionalEnvVars) { processStartInfo.EnvironmentVariables[entry.Key] = entry.Value; } } if (!string.IsNullOrEmpty(_pathExtension)) { var path = Utils.GetExtendedPath(_pathExtension); if (processStartInfo.EnvironmentVariables.ContainsKey("PATH")) { path += $";{processStartInfo.EnvironmentVariables["PATH"]}"; } processStartInfo.EnvironmentVariables["PATH"] = path; } Process process = Process.Start(processStartInfo); if (process != null) { _reportProcessId?.Invoke(process.Id); } try { var waiter = new ProcessWaiter(process); if (printTestOutput) { _logger.LogInfo(String.Format(Resources.OutputOfCommandMessage, "", command, param)); } ReadTheStream(process, output, printTestOutput, throwIfError); if (printTestOutput) { _logger.LogInfo(String.Format(Resources.EndOfOutputMessage, "")); } return(waiter.WaitForExit()); } finally { process?.Dispose(); } }
private int LaunchProcessWithDebuggerAttached(string workingDirectory, IDictionary <string, string> envVars, string command, string param, bool printTestOutput, IDebuggedProcessLauncher handle) { _logger.LogInfo(String.Format(Resources.AttachDebuggerMessage, command)); if (printTestOutput) { _logger.DebugInfo(Resources.DebuggerAttachedOutputMessage); } _processId = handle.LaunchProcessWithDebuggerAttached(command, workingDirectory, envVars, param, _settings.GetPathExtension(command)); Process process = Process.GetProcessById(_processId.Value); var waiter = new ProcessWaiter(process); waiter.WaitForExit(); process.Dispose(); return(waiter.ProcessExitCode); }
private int LaunchProcessWithDebuggerAttached(string workingDirectory, string command, string param, bool printTestOutput, IDebuggedProcessLauncher handle) { _logger.LogInfo("Attaching debugger to " + command); if (printTestOutput) { _logger.DebugInfo( "Note that due to restrictions of the VS Unit Testing framework, the test executable's output can not be displayed in the test console when debugging tests!"); } int processId = handle.LaunchProcessWithDebuggerAttached(command, workingDirectory, param, _settings.GetPathExtension(command)); Process process = Process.GetProcessById(processId); var waiter = new ProcessWaiter(process); waiter.WaitForExit(); process.Dispose(); return(waiter.ProcessExitCode); }
private int LaunchProcess(string workingDirectory, string command, string param, bool printTestOutput, bool throwIfError, List <string> output) { var processStartInfo = new ProcessStartInfo(command, param) { StandardOutputEncoding = Encoding.Default, RedirectStandardOutput = true, RedirectStandardError = false, UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = workingDirectory }; if (!string.IsNullOrEmpty(_pathExtension)) { processStartInfo.EnvironmentVariables["PATH"] = Utils.GetExtendedPath(_pathExtension); } Process process = Process.Start(processStartInfo); if (process != null) { _reportProcessId?.Invoke(process.Id); } try { var waiter = new ProcessWaiter(process); if (printTestOutput) { _logger.LogInfo( ">>>>>>>>>>>>>>> Output of command '" + command + " " + param + "'"); } ReadTheStream(process, output, printTestOutput, throwIfError); if (printTestOutput) { _logger.LogInfo("<<<<<<<<<<<<<<< End of Output"); } return(waiter.WaitForExit()); } finally { process?.Dispose(); } }