@@ -3341,9 +3341,6 @@ def do_history(self, args: argparse.Namespace) -> None:
33413341 except Exception as e :
33423342 self .perror ('Saving {!r} - {}' .format (args .output_file , e ), traceback_war = False )
33433343 elif args .transcript :
3344- if self .redirecting :
3345- self .perror ("Redirection not supported while using history -t" , traceback_war = False )
3346- return
33473344 self ._generate_transcript (history , args .transcript )
33483345 else :
33493346 # Display the history items retrieved
@@ -3353,6 +3350,16 @@ def do_history(self, args: argparse.Namespace) -> None:
33533350 def _generate_transcript (self , history : List [Union [HistoryItem , str ]], transcript_file : str ) -> None :
33543351 """Generate a transcript file from a given history of commands."""
33553352 import io
3353+ # Validate the transcript file path to make sure directory exists and write access is available
3354+ transcript_path = os .path .abspath (os .path .expanduser (transcript_file ))
3355+ transcript_dir = os .path .dirname (transcript_path )
3356+ if not os .path .isdir (transcript_dir ):
3357+ self .perror ("Transcript directory {!r} is not a directory" .format (transcript_dir ), traceback_war = False )
3358+ return
3359+ if not os .access (transcript_dir , os .W_OK ):
3360+ self .perror ("No write access for transcript directory {!r}" .format (transcript_dir ), traceback_war = False )
3361+ return
3362+
33563363 # Disable echo while we manually redirect stdout to a StringIO buffer
33573364 saved_echo = self .echo
33583365 saved_stdout = self .stdout
@@ -3505,17 +3512,6 @@ def do_load(self, args: argparse.Namespace) -> None:
35053512 return
35063513
35073514 if args .record_transcript :
3508- if self .redirecting :
3509- self .perror ("Redirection not supported while using load -r" , traceback_war = False )
3510- return
3511- transcript_path = os .path .abspath (os .path .expanduser (args .record_transcript ))
3512- transcript_dir = os .path .dirname (transcript_path )
3513- if not os .path .isdir (transcript_dir ):
3514- self .perror ("{!r} is not a directory" .format (transcript_dir ), traceback_war = False )
3515- return
3516- if not os .access (transcript_dir , os .W_OK ):
3517- self .perror ("You do not have write access to directory '{!r}" .format (transcript_dir ), traceback_war = False )
3518- return
35193515 self ._generate_transcript (script_commands , os .path .expanduser (args .record_transcript ))
35203516 return
35213517
0 commit comments