@@ -1675,10 +1675,13 @@ def parseline(self, line: str) -> Tuple[str, str, str]:
16751675 statement = self .statement_parser .parse_command_only (line )
16761676 return statement .command , statement .args , statement .command_and_args
16771677
1678- def onecmd_plus_hooks (self , line : str ) -> bool :
1678+ def onecmd_plus_hooks (self , line : str , pyscript_bridge_call : bool = False ) -> bool :
16791679 """Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks.
16801680
16811681 :param line: line of text read from input
1682+ :param pyscript_bridge_call: This should only ever be set to True by PyscriptBridge to signify the beginning
1683+ of an app() call in a pyscript. It is used to enable/disable the storage of the
1684+ command's stdout.
16821685 :return: True if cmdloop() should exit, False otherwise
16831686 """
16841687 import datetime
@@ -1718,6 +1721,10 @@ def onecmd_plus_hooks(self, line: str) -> bool:
17181721 try :
17191722 # Get sigint protection while we set up redirection
17201723 with self .sigint_protection :
1724+ if pyscript_bridge_call :
1725+ # Start saving command's stdout at this point
1726+ self .stdout .pause_storage = False
1727+
17211728 redir_error , saved_state = self ._redirect_output (statement )
17221729 self .cur_pipe_proc_reader = saved_state .pipe_proc_reader
17231730
@@ -1763,6 +1770,10 @@ def onecmd_plus_hooks(self, line: str) -> bool:
17631770 if not already_redirecting :
17641771 self .redirecting = False
17651772
1773+ if pyscript_bridge_call :
1774+ # Stop saving command's stdout before command finalization hooks run
1775+ self .stdout .pause_storage = True
1776+
17661777 except EmptyStatement :
17671778 # don't do anything, but do allow command finalization hooks to run
17681779 pass
@@ -3022,11 +3033,10 @@ def _reset_py_display() -> None:
30223033 @with_argparser (py_parser , preserve_quotes = True )
30233034 def do_py (self , args : argparse .Namespace ) -> bool :
30243035 """Invoke Python command or shell"""
3025- from .pyscript_bridge import PyscriptBridge , CommandResult
3036+ from .pyscript_bridge import PyscriptBridge
30263037 if self ._in_py :
30273038 err = "Recursively entering interactive Python consoles is not allowed."
30283039 self .perror (err , traceback_war = False )
3029- self ._last_result = CommandResult ('' , err )
30303040 return False
30313041
30323042 try :
0 commit comments