diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-12 14:50:59 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-12 14:50:59 -0400 |
commit | 57c64c4045e9d3d6e06787b8ea7bafdc14a2fa13 (patch) | |
tree | 9374761ab1623cad0f13776e7221a430d1faf9f1 /cmd2/cmd2.py | |
parent | 6b8b63686dc1ab871952c75785898c31882ef8a4 (diff) | |
download | cmd2-git-57c64c4045e9d3d6e06787b8ea7bafdc14a2fa13.tar.gz |
Fixed UnsupportedOperation on fileno error when a shell command was one of the commands run while generating a transcript
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 121d39a5..8106891a 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3512,7 +3512,6 @@ class Cmd(cmd.Cmd): Generate a transcript file from a given history of commands :return: True if running of commands should stop """ - import io # Validate the transcript file path to make sure directory exists and write access is available transcript_path = os.path.abspath(os.path.expanduser(transcript_file)) transcript_dir = os.path.dirname(transcript_path) @@ -3554,21 +3553,16 @@ class Cmd(cmd.Cmd): else: command += '{}{}\n'.format(self.continuation_prompt, line) transcript += command - # create a new string buffer and set it to stdout to catch the output - # of the command - membuf = io.StringIO() - self.stdout = membuf + + # Use a StdSim object to capture output + self.stdout = utils.StdSim(self.stdout) # then run the command and let the output go into our buffer stop = self.onecmd_plus_hooks(history_item) commands_run += 1 - # rewind the buffer to the beginning - membuf.seek(0) - # get the output out of the buffer - output = membuf.read() - # and add the regex-escaped output to the transcript - transcript += output.replace('/', r'\/') + # add the regex-escaped output to the transcript + transcript += self.stdout.getvalue().replace('/', r'\/') # check if we are supposed to stop if stop: |