diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | cmd2/cmd2.py | 16 |
2 files changed, 7 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ac1cc89a..b6786706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * Fixed issue where quotes around redirection file paths were being lost in `Statement.expanded_command_line()` * Fixed a bug in how line numbers were calculated for transcript testing * Fixed issue where `_cmdloop()` suppressed exceptions by returning from within its `finally` code + * Fixed UnsupportedOperation on fileno error when a shell command was one of the commands run while generating + a transcript * Enhancements * Added capability to chain pipe commands and redirect their output (e.g. !ls -l | grep user | wc -l > out.txt) * `pyscript` limits a command's stdout capture to the same period that redirection does. 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: |