lib/bolt/transport/docker/connection.rb
# Executes a command inside the target container. This is called from the shell class.
#
# @param command [string] The command to run
Executes a command inside the target container. This is called from the shell class.
Executes a command inside the target container . This is called from the shell class .
def execute(command)
          args = []
          args += %w[--interactive]
          args += %w[--tty] if target.options['tty']
          args += @env_vars if @env_vars
          if target.options['shell-command'] && !target.options['shell-command'].empty?
            command = command.gsub('"', '\"')
            command = "#{target.options['shell-command']} \"#{command}\""
          end
          docker_command = %w[docker exec] + args + [container_id] + Shellwords.split(command)
          @logger.trace { "Executing: #{docker_command.join(' ')}" }
          Open3.popen3(env_hash, *docker_command)
        rescue StandardError
          @logger.trace { "Command aborted" }
          raise
        end
def execute ( command ) args = [ ] args += %w[ --interactive ] args += %w[ --tty ] if target . options [ 'tty' ] args += @env_vars if @env_vars if target . options [ 'shell-command' ] && ! target . options [ 'shell-command' ] . empty? command = command . gsub ( '"' , '\"' ) command = "#{target.options['shell-command']} \"#{command}\"" end docker_command = %w[ docker exec ] + args + [ container_id ] + Shellwords . split ( command ) @logger . trace { "Executing: #{docker_command.join(' ')}" } Open3 . popen3 ( env_hash , * docker_command ) rescue StandardError @logger . trace { "Command aborted" } raise end
Executes a command inside the target container.
Executes a command inside the target container .
# CODEREVIEW: Is it always safe to pass --interactive? # escape any double quotes in command
command
The command to run
The command to run