Changeset 2954

Show
Ignore:
Timestamp:
01/19/08 08:28:18 (11 months ago)
Author:
laurent.dufrechou
Message:

Shell command bug corrected thanks to new shell_cmd hook.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ipython/trunk/IPython/gui/wx/ipython_view.py

    r2934 r2954  
    108108         
    109109        #we replace the ipython default shell command caller by our shell handler 
    110     #FIXME: any better solution welcome 
    111         IPython.genutils.shell_ori = self._shell    #needed by windows 
    112         self._IP.system = self._shell           #needed for linux 
     110    self._IP.set_hook('shell_hook',self._shell) 
     111         
    113112        #we replace the ipython default input command caller by our method 
    114113        IPython.iplib.raw_input_original = self._raw_input 
     
    406405        sys.stdout = orig_stdout 
    407406     
    408     def _shell(self, cmd,verbose=0,debug=0,header=''): 
     407    def _shell(self, ip, cmd): 
    409408        ''' 
    410409        Replacement method to allow shell commands without them blocking. 
    411410 
     411        @param ip: Ipython instance, same as self._IP 
     412        @type cmd: Ipython instance 
    412413        @param cmd: Shell command to execute. 
    413414        @type cmd: string 
    414         @param verbose: Verbosity 
    415         @type verbose: integer 
    416         @param debug: Debug level 
    417         @type debug: integer 
    418         @param header: Header to be printed before output 
    419         @type header: string 
    420         ''' 
    421         if verbose or debug: print header+cmd 
    422         # flush stdout so we don't mangle python's buffering 
    423         if not debug: 
    424             stdin, stdout = os.popen4(cmd) 
    425             result = stdout.read().decode('cp437').encode(locale.getpreferredencoding()) 
    426             #we use print command because the shell command is called inside IPython instance and thus is 
    427             #redirected to thread cout 
    428             #"\x01\x1b[1;36m\x02" <-- add colour to the text... 
    429             print "\x01\x1b[1;36m\x02"+result 
    430             stdout.close() 
    431             stdin.close() 
     415        ''' 
     416        stdin, stdout = os.popen4(cmd) 
     417        result = stdout.read().decode('cp437').encode(locale.getpreferredencoding()) 
     418        #we use print command because the shell command is called inside IPython instance and thus is 
     419        #redirected to thread cout 
     420        #"\x01\x1b[1;36m\x02" <-- add colour to the text... 
     421        print "\x01\x1b[1;36m\x02"+result 
     422        stdout.close() 
     423        stdin.close() 
    432424 
    433425class WxConsoleView(stc.StyledTextCtrl):