Commit 62e4e1ce authored by Antoine Millet's avatar Antoine Millet
Browse files

Added stdin argument to execute_command

parent 415a9189
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -278,16 +278,18 @@ class Handler(BasePlugin):
            logger.debug('Plugins state saved')

    @rpc_handler
    def execute_command(self, command):
    def execute_command(self, command, stdin=None):
        """Execute an arbitrary shell command on the host.

        :param string command: shell command to run
        :param string stdin: string to use as stdin on command
        """
        logger.debug('Executing command %s', command)

        try:
            remote_command = EvPopen(self.main, command, close_fds=True,
                                     shell=True, stdout=PIPE, stderr=STDOUT)
                                     shell=True, stdout=PIPE, stdin=PIPE,
                                     stderr=STDOUT)
        except Exception:
            logger.exception('Error while starting subprocess for executing '
                             ' command %s', command)
@@ -296,7 +298,7 @@ class Handler(BasePlugin):
        self.commands.add(remote_command)

        try:
            stdout, _ = remote_command.communicate()
            stdout, _ = remote_command.communicate(stdin)
        except Exception:
            logger.exception('Error while communicating with subprocess for'
                             ' command %s', command)