def run_command(self, command, exitcode=None):
        """
        Run a command and return its output.
        :param command: command to run
        :type command: str
        :param exitcode: expected exitcode, None to ignore
        :type exitcode: int or None
        :return: output of the command
        :rtype: str
        """
        # for debug purposes, locate script
        try:
            scriptname = command.split(" ")[0]
            scriptfile = self.stash.runtime.find_script_file(scriptname)
            self.logger.debug(u"Scriptfile for command: " + str(scriptfile))
        except Exception as e:
            self.logger.warning(u"Could not find script for command: " + repr(e))
            # do NOT return here, script may be alias
        outs = StringIO()
        self.logger.info(u"Executing: " + repr(command))
        worker = self.stash(
            command,
            persistent_level=1,
            final_outs=outs,
            final_errs=outs,
            cwd=self.cwd
        )  # 1 for mimicking running from console
        output = outs.getvalue()
        returnvalue = worker.state.return_value
        self.logger.debug(output)
        self.logger.debug("Exitcode: " + str(returnvalue))
        if exitcode is not None:
            self.assertEqual(
                returnvalue,
                exitcode,
                u"unexpected exitcode ({e} expected, got {g})\nOutput:\n{o}\n".format(e=exitcode,
                                                                                      g=returnvalue,
                                                                                      o=output),
            )
        return output

        Run a command and return its output.
        :param command: command to run
        :type command: str
        :param exitcode: expected exitcode, None to ignore
        :type exitcode: int or None
        :return: output of the command
        :rtype: str
        
tests/stashtest.py