private (int exitCode, string output, string error) runMigratorProcess(IMigratorParams commandParams) { var output = string.Empty; var error = string.Empty; var result = new ProcessRunner { OutputDataCallback = (p, msg) => output = msg, ErrorDataCallback = (p, msg) => error = msg } .Execute(commandParams); return(result, output, error); }
public int Execute(IMigratorParams migratorParams) { _currentParams = migratorParams; try { using (var process = new Process()) { try { process.StartInfo = new ProcessStartInfo("dotnet") { Arguments = $"\"{Constants.MigratorAssembly}\" {migratorParams.ToArgumentString()}", #if !DEBUG WorkingDirectory = Path.GetDirectoryName(typeof(ProcessRunner).Assembly.Location), #endif CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; process.OutputDataReceived += onOutputDataReceived; process.ErrorDataReceived += onErrorDataReceived; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); } finally { process.OutputDataReceived -= onOutputDataReceived; process.ErrorDataReceived -= onErrorDataReceived; } return(process.ExitCode); } } catch (Exception ex) { OutputDataCallback?.Invoke(_currentParams, ex.Message); return(ExitCode.Exception); } }