summaryrefslogtreecommitdiff
path: root/cmd2/pyscript_bridge.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-04-24 12:58:47 -0400
committerGitHub <noreply@github.com>2019-04-24 12:58:47 -0400
commit7a20c2e312513b8a84a6cfb56263cac9c67df04d (patch)
tree679d8dc86e5ac5f38d57133664ca48f04e217239 /cmd2/pyscript_bridge.py
parent63343ad3f013d0d8c836014538439056585851ef (diff)
parentb4dd7896b1a18228282a616d88c01ae37fd39419 (diff)
downloadcmd2-git-7a20c2e312513b8a84a6cfb56263cac9c67df04d.tar.gz
Merge pull request #663 from python-cmd2/pyscript_capture
Pyscript now saves command output during the same period that redirection does
Diffstat (limited to 'cmd2/pyscript_bridge.py')
-rw-r--r--cmd2/pyscript_bridge.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index a4eaf308..1c720cf9 100644
--- a/cmd2/pyscript_bridge.py
+++ b/cmd2/pyscript_bridge.py
@@ -62,11 +62,9 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr
class PyscriptBridge(object):
- """Preserves the legacy 'cmd' interface for pyscript while also providing a new python API wrapper for
- application commands."""
+ """Provides a Python API wrapper for application commands."""
def __init__(self, cmd2_app):
self._cmd2_app = cmd2_app
- self._last_result = None
self.cmd_echo = False
def __dir__(self):
@@ -89,6 +87,9 @@ class PyscriptBridge(object):
# This will be used to capture _cmd2_app.stdout and sys.stdout
copy_cmd_stdout = StdSim(self._cmd2_app.stdout, echo)
+ # Pause the storing of stdout until onecmd_plus_hooks enables it
+ copy_cmd_stdout.pause_storage = True
+
# This will be used to capture sys.stderr
copy_stderr = StdSim(sys.stderr, echo)
@@ -98,7 +99,7 @@ class PyscriptBridge(object):
self._cmd2_app.stdout = copy_cmd_stdout
with redirect_stdout(copy_cmd_stdout):
with redirect_stderr(copy_stderr):
- self._cmd2_app.onecmd_plus_hooks(command)
+ self._cmd2_app.onecmd_plus_hooks(command, pyscript_bridge_call=True)
finally:
self._cmd2_app.stdout = copy_cmd_stdout.inner_stream