Exemple #1
0
        /// <summary>
        /// Executes a command and arguments in the specified shell.
        /// </summary>
        /// <param name="executable">The executable name or path.</param>
        /// <param name="arguments">The arguments to be passed to the executable (which will be space-separated).</param>
        /// <exception cref="ExecutionFailedException">Thrown when the exit code of the execution is non-zero.</exception>
        /// <returns>A task which results in an <see cref="ICommandResult"/> (i.e., the result of the command execution).</returns>
        public virtual async Task <ICommandResult> ExecuteCommandAsync(string executable, IEnumerable <string> arguments)
        {
            var command          = _shell;
            var commandArguments =
                _commandPrefix == null?
                this.GetCommandArgument($"{executable} {string.Join(" ", arguments)}") :
                    this.GetCommandArgument($"{_commandPrefix} {executable} {string.Join(" ", arguments)}");

            var result = await Helpers.RunCommand(
                command,
                commandArguments,
                _standardInputs,
                _standardOutputHandlers,
                _standardErrorHandlers,
                _inputRequestHandler,
                _observableCommandEvent,
                _cancellationTokens,
                _standardOutputEncoding,
                _standardErrorEncoding,
                _startInfoTransform).ConfigureAwait(false);

            if (_throws && result.ExitCode != 0)
            {
                var error = new ExecutionFailedException($"The execution resulted in a non-zero exit code ({result.ExitCode}).", result);
                _observableCommandEvent.FireError(error);
                throw error;
            }

            // TODO: Add a `UseSubscribeComplete` (or something like it) that instructs the observable to complete here.
            //_observableCommandEvent.FireCompleted();

            return(result);
        }
Exemple #2
0
        public void execution_exception_prints_error_text_and_exit_code_in_message()
        {
            var exc = new ExecutionFailedException(220, "error was such and such");

            StringAssert.Contains("Operation exited with exit code 220.", exc.Message);
            StringAssert.Contains("The error message was as follows:\n error was such and such", exc.Message);
        }
 public void execution_exception_prints_error_text_and_exit_code_in_message()
 {
     var exc = new ExecutionFailedException(220, "error was such and such");
     StringAssert.Contains("Operation exited with exit code 220.", exc.Message);
     StringAssert.Contains("The error message was as follows:\n error was such and such", exc.Message);
 }