public async Task <ProcessResult> RunAsync(ProcessRunInfo info, CancellationToken token = default(CancellationToken)) { using (var process = Start(info)) { if (process == null) { throw new ApplicationException("Failed to start process!"); } var p = process; using (token.Register(() => p.Kill())) { var readOutTask = ReadToOutput(process.StandardOutput, ConsoleColor.Gray, token); var readErrorTask = ReadToOutput(process.StandardError, ConsoleColor.DarkYellow, token); await Task.Run(() => p.WaitForExit(), token); await Task.WhenAll(readOutTask, readErrorTask); return(new ProcessResult { ExitCode = process.ExitCode, Output = readOutTask.Result, Error = readErrorTask.Result, }); } } }
public async Task <ProcessResult> RunAsync(ProcessRunInfo info, CancellationToken cancelToken = default(CancellationToken)) { var runner = new ProcessRunner(context); var result = await runner.RunAsync(info, cancelToken); ProcessResult(result); return(result); }
public ProcessResult Run(ProcessRunInfo info, CancellationToken cancelToken = default(CancellationToken)) { var runner = new ProcessRunner(context); var result = runner.Run(info, cancelToken); ProcessResult(result); return(result); }
public async Task <ProcessResult> RunAsync(string command, CancellationToken cancelToken = default(CancellationToken)) { var runner = new ProcessRunner(context); var arguments = ProcessRunInfo.FromCommand(command); var result = await runner.RunAsync(arguments, cancelToken); ProcessResult(result); return(result); }
public ProcessResult Run(string command, CancellationToken cancelToken = default(CancellationToken)) { var runner = new ProcessRunner(context); var arguments = ProcessRunInfo.FromCommand(command); var result = runner.Run(arguments, cancelToken); ProcessResult(result); return(result); }
protected ProcessRunInfo GetProcessArgs(string arguments) { var info = new ProcessRunInfo { Filename = Exe, Arguments = arguments, EchoCommand = EchoCommand, }; if (!string.IsNullOrEmpty(WorkingDirectory)) { info.WorkingDirectory = WorkingDirectory; } return(info); }
public SysProcess Start(ProcessRunInfo info) { if (info.Filename == null) { throw new ArgumentNullException(nameof(info.Filename)); } var startInfo = new ProcessStartInfo { FileName = info.Filename, Arguments = info.Arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, }; if (!string.IsNullOrEmpty(info.WorkingDirectory)) { startInfo.WorkingDirectory = info.WorkingDirectory; var parts = info.Filename.Split(Path.DirectorySeparatorChar); var firstPart = parts.FirstOrDefault(); if (firstPart == "." || firstPart == "..") { var _p = Path.Combine(info.WorkingDirectory, info.Filename); startInfo.FileName = Path.GetFullPath(_p); } } foreach (var key in info.EnvironmentVariables.Keys) { startInfo.EnvironmentVariables[key] = info.EnvironmentVariables[key]; } Output?.WriteActionBlock(context, $"Run Command: {info.Filename} {info.Arguments}"); return(SysProcess.Start(startInfo)); }