Skip to content

Commit 57c64c4

Browse files
committed
Fixed UnsupportedOperation on fileno error when a shell command was one of the commands run while generating a transcript
1 parent 6b8b636 commit 57c64c4

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Fixed issue where quotes around redirection file paths were being lost in `Statement.expanded_command_line()`
1111
* Fixed a bug in how line numbers were calculated for transcript testing
1212
* Fixed issue where `_cmdloop()` suppressed exceptions by returning from within its `finally` code
13+
* Fixed UnsupportedOperation on fileno error when a shell command was one of the commands run while generating
14+
a transcript
1315
* Enhancements
1416
* Added capability to chain pipe commands and redirect their output (e.g. !ls -l | grep user | wc -l > out.txt)
1517
* `pyscript` limits a command's stdout capture to the same period that redirection does.

cmd2/cmd2.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,7 +3512,6 @@ def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcrip
35123512
Generate a transcript file from a given history of commands
35133513
:return: True if running of commands should stop
35143514
"""
3515-
import io
35163515
# Validate the transcript file path to make sure directory exists and write access is available
35173516
transcript_path = os.path.abspath(os.path.expanduser(transcript_file))
35183517
transcript_dir = os.path.dirname(transcript_path)
@@ -3554,21 +3553,16 @@ def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcrip
35543553
else:
35553554
command += '{}{}\n'.format(self.continuation_prompt, line)
35563555
transcript += command
3557-
# create a new string buffer and set it to stdout to catch the output
3558-
# of the command
3559-
membuf = io.StringIO()
3560-
self.stdout = membuf
3556+
3557+
# Use a StdSim object to capture output
3558+
self.stdout = utils.StdSim(self.stdout)
35613559

35623560
# then run the command and let the output go into our buffer
35633561
stop = self.onecmd_plus_hooks(history_item)
35643562
commands_run += 1
35653563

3566-
# rewind the buffer to the beginning
3567-
membuf.seek(0)
3568-
# get the output out of the buffer
3569-
output = membuf.read()
3570-
# and add the regex-escaped output to the transcript
3571-
transcript += output.replace('/', r'\/')
3564+
# add the regex-escaped output to the transcript
3565+
transcript += self.stdout.getvalue().replace('/', r'\/')
35723566

35733567
# check if we are supposed to stop
35743568
if stop:

0 commit comments

Comments
 (0)