Esempio n. 1
0
        public override void BeginExecuteAsyncCommand(string commandText, bool runInShell, IDebugUnixShellCommandCallback callback, out IDebugUnixShellAsyncCommand asyncCommand)
        {
            if (IsClosed)
            {
                throw new ObjectDisposedException(nameof(PipeConnection));
            }

            // Assume in the Begin Async that we are expecting raw output from the process
            var commandRunner = GetExecCommandRunner(commandText, handleRawOutput: true);

            asyncCommand = new DockerAsyncCommand(commandRunner, callback);
        }
Esempio n. 2
0
        public int ExecuteCommand(string commandText, int timeout, out string commandOutput, out string errorMessage, bool runInShell = true, bool makeInteractive = true)
        {
            commandOutput = string.Empty;
            errorMessage  = string.Empty;
            if (_currentCommand != null)
            {
                throw new InvalidOperationException("already a command processing");
            }
            _commandCompleteEvent.Reset();

            using (ICommandRunner commandRunner = GetExecCommandRunner(commandText, runInShell, makeInteractive))
            {
                ShellCommandCallback commandCallback = new ShellCommandCallback(_commandCompleteEvent);
                DockerAsyncCommand   command         = new DockerAsyncCommand(commandRunner, commandCallback);

                try
                {
                    _currentCommand = command;
                    if (!_commandCompleteEvent.WaitOne(timeout))
                    {
                        errorMessage = StringResources.Error_OperationTimedOut;
                        return(ExitCodes.OPERATION_TIMEDOUT); // ERROR_TIMEOUT
                    }

                    commandOutput = commandCallback.CommandOutput.Trim('\n', '\r'); // trim ending newlines
                    errorMessage  = _currentCommand.ErrorMessage;
                    return(commandCallback.ExitCode);
                }
                catch (ObjectDisposedException ode)
                {
                    Debug.Fail("Why are we operating on a disposed object?");
                    errorMessage = ode.ToString();
                    return(ExitCodes.OBJECTDISPOSED);
                }
                catch (Exception e)
                {
                    Debug.Fail(e.Message);
                    errorMessage = e.ToString();
                    return(-1);
                }
                finally
                {
                    _currentCommand.Close();
                    _currentCommand = null;
                }
            }
        }