comparison 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
comparison
equal deleted inserted replaced
20:c8efa4369189 32:e72eb9137a87
70 editor = os.environ.get('EDITOR') 70 editor = os.environ.get('EDITOR')
71 if not editor: 71 if not editor:
72 if sys.platform[:3] == 'win': 72 if sys.platform[:3] == 'win':
73 editor = 'notepad' 73 editor = 'notepad'
74 else: 74 else:
75 for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']: 75 for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico', 'vi']:
76 if not os.system('which %s' % (editor)): 76 if not os.system('which %s' % (editor)):
77 break 77 break
78 78
79 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive'] 79 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive']
80 terminators = ';\n' 80 terminators = ';\n'
158 statekeeper = None 158 statekeeper = None
159 statement, redirect, mode = self.parseRedirectors(statement) 159 statement, redirect, mode = self.parseRedirectors(statement)
160 if redirect: 160 if redirect:
161 if mode in ('w','a'): 161 if mode in ('w','a'):
162 statekeeper = Statekeeper(self, ('stdout',)) 162 statekeeper = Statekeeper(self, ('stdout',))
163 self.stdout = open(redirect, mode) 163 try:
164 self.stdout = open(redirect, mode)
165 except IOError, e:
166 print str(e)
167 return 0
164 else: 168 else:
165 statement = '%s %s' % (statement, self.fileimport(statement=statement, source=redirect)) 169 statement = '%s %s' % (statement, self.fileimport(statement=statement, source=redirect))
166 stop = cmd.Cmd.onecmd(self, statement) 170 stop = cmd.Cmd.onecmd(self, statement)
167 try: 171 try:
168 if command not in self.excludeFromHistory: 172 if command not in self.excludeFromHistory: