public virtual async Task Run()

in src/AWS.Deploy.ServerMode.Client/CommandLineWrapper.cs [24:88]


        public virtual async Task<RunResult> Run(string command, params string[] stdIn)
        {
            var arguments = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"/c {command}" : $"-c \"{command}\"";

            var strOutput = new CappedStringBuilder(100);
            var strError = new CappedStringBuilder(50);

            var processStartInfo = new ProcessStartInfo
            {
                FileName = GetSystemShell(),
                Arguments = arguments,
                UseShellExecute = false, // UseShellExecute must be false in allow redirection of StdIn.
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = !_diagnosticLoggingEnabled, // It allows displaying stdout and stderr on the screen.
            };

            var process = Process.Start(processStartInfo);
            if (process == null)
            {
                throw new InvalidOperationException();
            }

            try
            {
                foreach (var line in stdIn)
                {
                    await process.StandardInput.WriteLineAsync(line).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                process.Kill();

                return await Task.FromResult(new RunResult
                {
                    ExitCode = -1,
                    StandardError = ex.Message
                }).ConfigureAwait(false);
            }

            process.OutputDataReceived += (sender, e) =>
            {
                strOutput.AppendLine(e.Data);
            };

            process.ErrorDataReceived += (sender, e) =>
            {
                strError.AppendLine(e.Data);
            };
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            process.WaitForExit(-1);

            var result = new RunResult
            {
                ExitCode = process.ExitCode,
                StandardError = strError.ToString(),
                StandardOut = strOutput.GetLastLines(5),
            };

            return await Task.FromResult(result).ConfigureAwait(false);
        }