@@ -199,7 +199,7 @@ class Cmd(cmd.Cmd):
199199
200200 def __init__ (self , completekey : str = 'tab' , stdin = None , stdout = None , * ,
201201 persistent_history_file : str = '' , persistent_history_length : int = 1000 ,
202- startup_script : str = '' , use_ipython : bool = False ,
202+ startup_script : str = '' , silent_startup_script : bool = False , use_ipython : bool = False ,
203203 allow_cli_args : bool = True , transcript_files : Optional [List [str ]] = None ,
204204 allow_redirection : bool = True , multiline_commands : Optional [List [str ]] = None ,
205205 terminators : Optional [List [str ]] = None , shortcuts : Optional [Dict [str , str ]] = None ,
@@ -215,6 +215,8 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
215215 :param persistent_history_length: max number of history items to write
216216 to the persistent history file
217217 :param startup_script: file path to a script to execute at startup
218+ :param silent_startup_script: if ``True``, then the startup script's output will be
219+ suppressed. Anything written to stderr will still display.
218220 :param use_ipython: should the "ipy" command be included for an embedded IPython shell
219221 :param allow_cli_args: if ``True``, then :meth:`cmd2.Cmd.__init__` will process command
220222 line arguments as either commands to be run or, if ``-t`` or
@@ -363,7 +365,10 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
363365 if startup_script :
364366 startup_script = os .path .abspath (os .path .expanduser (startup_script ))
365367 if os .path .exists (startup_script ):
366- self ._startup_commands .append ("run_script {}" .format (utils .quote_string (startup_script )))
368+ script_cmd = "run_script {}" .format (utils .quote_string (startup_script ))
369+ if silent_startup_script :
370+ script_cmd += "> {}" .format (os .devnull )
371+ self ._startup_commands .append (script_cmd )
367372
368373 # Transcript files to run instead of interactive command loop
369374 self ._transcript_files = None # type: Optional[List[str]]
0 commit comments