'Executes a single command.'

def execute(self, command, stdout=None, stderr=None):

    if (not self.active):
        return 0
    if (type(command) == type('')):
        command = self.subst(command)
        cmdargs = shlex.split(command)
        if (cmdargs[0] == 'cd'):
            command = ((os.chdir,) + tuple(cmdargs[1:]))
    if (type(command) == type(())):
        func = command[0]
        args = command[1:]
        return func(*args)
    else:
        if (stdout is sys.stdout):
            subout = None
        else:
            subout = subprocess.PIPE
        if (stderr is sys.stderr):
            suberr = None
        elif (stderr is None):
            suberr = subprocess.STDOUT
        else:
            suberr = subprocess.PIPE
        p = subprocess.Popen(command, shell=(sys.platform == 'win32'), stdout=subout, stderr=suberr)
        p.wait()
        if (stdout is None):
            self.stdout = p.stdout.read()
        elif (stdout is not sys.stdout):
            stdout.write(p.stdout.read())
        if (stderr not in (None, sys.stderr)):
            stderr.write(p.stderr.read())
        return p.returncode
