'output FILENAME: Send output to FILENAME (or stdout)
If the FILENAME is stdout then output is sent to standard
output from when the shell was started.  The file is opened
using the current encoding (change with .encoding command).'

def command_output(self, cmd):

    self.stdout.flush()
    self.stderr.flush()
    if hasattr(self.stdin, 'flush'):
        try:
            self.stdin.flush()
        except IOError:
            pass
    if (len(cmd) != 1):
        raise self.Error('You    must    specify    a    filename')
    try:
        fname = cmd[0]
        if (fname == 'stdout'):
            old = None
            if (self.stdout != self._original_stdout):
                old = self.stdout
            self.stdout = self._original_stdout
            if (old is not None):
                old.close()
            return
        newf = codecs.open(fname, 'w', self.encoding[0], self.encoding[1])
        old = None
        if (self.stdout != self._original_stdout):
            old = self.stdout
        self.stdout = newf
        if (old is not None):
            old.close()
    finally:
        self._out_colour()
