summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-07 16:52:17 -0700
committerGitHub <noreply@github.com>2018-06-07 16:52:17 -0700
commite4d13c745b7b983eb444e97f467b572a885d220c (patch)
tree97aa7c7151cc8f5c6923d0d965d650af75d7115e /cmd2/cmd2.py
parentdde5207c22d041b97981de47758317d15a3fc329 (diff)
parentd0e71c85190b81bb269cc18bf9380a142e18d707 (diff)
downloadcmd2-git-e4d13c745b7b983eb444e97f467b572a885d220c.tar.gz
Merge branch 'master' into autocompleter
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 94773794..bb4ac4ad 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1710,7 +1710,7 @@ class Cmd(cmd.Cmd):
if self.timing:
self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart))
finally:
- if self.allow_redirection:
+ if self.allow_redirection and self.redirecting:
self._restore_output(statement)
except EmptyStatement:
pass
@@ -1854,7 +1854,11 @@ class Cmd(cmd.Cmd):
# REDIRECTION_APPEND or REDIRECTION_OUTPUT
if statement.output == constants.REDIRECTION_APPEND:
mode = 'a'
- sys.stdout = self.stdout = open(os.path.expanduser(statement.output_to), mode)
+ try:
+ sys.stdout = self.stdout = open(os.path.expanduser(statement.output_to), mode)
+ except OSError as ex:
+ self.perror('Not Redirecting because - {}'.format(ex), traceback_war=False)
+ self.redirecting = False
else:
# going to a paste buffer
sys.stdout = self.stdout = tempfile.TemporaryFile(mode="w+")
@@ -2892,16 +2896,19 @@ a..b, a:b, a:, ..b items by indices (inclusive)
self.echo = saved_echo
# finally, we can write the transcript out to the file
- with open(transcript_file, 'w') as fout:
- fout.write(transcript)
-
- # and let the user know what we did
- if len(history) > 1:
- plural = 'commands and their outputs'
+ try:
+ with open(transcript_file, 'w') as fout:
+ fout.write(transcript)
+ except OSError as ex:
+ self.perror('Failed to save transcript: {}'.format(ex), traceback_war=False)
else:
- plural = 'command and its output'
- msg = '{} {} saved to transcript file {!r}'
- self.pfeedback(msg.format(len(history), plural, transcript_file))
+ # and let the user know what we did
+ if len(history) > 1:
+ plural = 'commands and their outputs'
+ else:
+ plural = 'command and its output'
+ msg = '{} {} saved to transcript file {!r}'
+ self.pfeedback(msg.format(len(history), plural, transcript_file))
@with_argument_list
def do_edit(self, arglist):