private FlywayOutputResult Exec(string command, FlywayOptionGroup options) { if (string.IsNullOrWhiteSpace(command)) { throw new Exception("Command is invalid!"); } if (options != null && !options.Validate()) { throw new Exception("Command options are invalid!"); } FlywayOutputReader outputReader = new FlywayOutputReader(); Process process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardInput = false; process.StartInfo.WorkingDirectory = _flywayPath; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = $"/c flyway {(options != null ? options.ToArgs() : "")} {command} "; process.OutputDataReceived += outputReader.OnOutputDataReceived; process.ErrorDataReceived += outputReader.OnErrorDataReceived; process.Start(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); process.WaitForExit(); process.Dispose(); return(outputReader.ToOutputResult()); }
private Task <FlywayOutputResult> ExecAsync(string command, FlywayOptionGroup options) { return(Task.Run(() => Exec(command, options))); }