(self, cmd)
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).
output FILENAME: Send output to FILENAME (or stdout)
output FILENAME : Send output to FILENAME ( or stdout )
def command_output(self, cmd):
        """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).
        """
        # Flush everything
        self.stdout.flush()
        self.stderr.flush()
        if hasattr(self.stdin, "flush"):
            try:
                self.stdin.flush()
            except IOError:  # see issue 117
                pass

        # we will also close stdout but only do so once we have a
        # replacement so that stdout is always valid

        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:  # done here in case close raises exception
                    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()
def command_output ( self , cmd ) : # Flush everything self . stdout . flush ( ) self . stderr . flush ( ) if hasattr ( self . stdin , "flush" ) : try : self . stdin . flush ( ) except IOError : # see issue 117 pass # we will also close stdout but only do so once we have a # replacement so that stdout is always valid 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 : # done here in case close raises exception 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 ( )