diff cmd2.py @ 32:e72eb9137a87

trying fix for IOError crash in redirect
author catherine.devlin@gmail.com
date Fri, 16 May 2008 10:40:15 -0400
parents c8efa4369189
children f472921d6189
line wrap: on
line diff
--- a/cmd2.py	Thu May 15 17:38:15 2008 -0400
+++ b/cmd2.py	Fri May 16 10:40:15 2008 -0400
@@ -72,7 +72,7 @@
         if sys.platform[:3] == 'win':
             editor = 'notepad'
         else:
-            for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']:
+            for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico', 'vi']:
                 if not os.system('which %s' % (editor)):
                     break
             
@@ -160,7 +160,11 @@
         if redirect:
             if mode in ('w','a'):
                 statekeeper = Statekeeper(self, ('stdout',))
-                self.stdout = open(redirect, mode)            
+                try:
+                    self.stdout = open(redirect, mode)            
+                except IOError, e:
+                    print str(e)
+                    return 0
             else:
                 statement = '%s %s' % (statement, self.fileimport(statement=statement, source=redirect))
         stop = cmd.Cmd.onecmd(self, statement)
@@ -520,4 +524,4 @@
             setattr(self, attrib, getattr(self.obj, attrib))
     def restore(self):
         for attrib in self.attribs:
-            setattr(self.obj, attrib, getattr(self, attrib))        
+            setattr(self.obj, attrib, getattr(self, attrib))        
\ No newline at end of file