@@ -3002,27 +3002,38 @@ def do_history(self, args):
30023002 except Exception as e :
30033003 self .perror ('Saving {!r} - {}' .format (args .output_file , e ), traceback_war = False )
30043004 elif args .transcript :
3005+ membuf = io .StringIO ()
3006+
30053007 # Make sure echo is on so commands print to standard out
30063008 saved_echo = self .echo
3007- self .echo = True
3009+ self .echo = False
30083010
30093011 # Redirect stdout to the transcript file
30103012 saved_self_stdout = self .stdout
3011- self .stdout = open ( args . transcript , 'w' )
3013+ self .stdout = membuf
30123014
30133015 # Run all of the commands in the history with output redirected to transcript and echo on
3014- self .runcmds_plus_hooks (history )
3016+ for history_item in history :
3017+ # write the command to the output stream
3018+ first = True
3019+ for line in history_item .splitlines ():
3020+ if first :
3021+ self .stdout .write ('{}{}\n ' .format (self .prompt , line ))
3022+ first = False
3023+ else :
3024+ self .stdout .write ('{}{}\n ' .format (self .continuation_prompt , line ))
3025+ self .onecmd_plus_hooks (history_item )
30153026
30163027 # Restore stdout to its original state
3017- self .stdout .close ()
3028+ # self.stdout.close()
30183029 self .stdout = saved_self_stdout
30193030
30203031 # Set echo back to its original state
30213032 self .echo = saved_echo
30223033
30233034 # Post-process the file to escape un-escaped "/" regex escapes
3024- with open ( args . transcript , 'r' ) as fin :
3025- data = fin .read ()
3035+ membuf . seek ( 0 )
3036+ data = membuf .read ()
30263037 post_processed_data = data .replace ('/' , '\/' )
30273038 with open (args .transcript , 'w' ) as fout :
30283039 fout .write (post_processed_data )
0 commit comments