From 9dac02ad443bcf9a9e742ef6a5defcba10792ebb Mon Sep 17 00:00:00 2001 From: Ben Wade Date: Tue, 4 Mar 2025 16:55:00 -0700 Subject: [PATCH 1/2] Add print_output parameter --- sling/sling/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sling/sling/__init__.py b/sling/sling/__init__.py index d5d896b..62f15c3 100644 --- a/sling/sling/__init__.py +++ b/sling/sling/__init__.py @@ -574,9 +574,13 @@ def stream(self, env:dict=None, stdin=None) -> Iterable[list]: # conform to legacy module Sling = Task -def _run(cmd: str, temp_file: str, return_output=False, env:dict=None, stdin=None): +def _run(cmd: str, temp_file: str, return_output=False, print_output=True, env:dict=None, stdin=None): """ - Runs the task. Use `return_output` as `True` to return the stdout+stderr output at end. `env` accepts a dictionary which defines the environment. + Runs the task. + + Use `return_output` as `True` to return the stdout+stderr output at end. + Use `print_output` as `True` to print to stdout as it runs. + `env` accepts a dictionary which defines the environment. """ lines = [] try: @@ -587,7 +591,7 @@ def _run(cmd: str, temp_file: str, return_output=False, env:dict=None, stdin=Non for line in _exec_cmd(cmd, env=env, stdin=stdin): if return_output: lines.append(line) - else: + if print_output: print(line, flush=True) os.remove(temp_file) From 1909a2d3494db228f3511f9dc9d11f09a363c87a Mon Sep 17 00:00:00 2001 From: Ben Wade Date: Tue, 4 Mar 2025 18:07:22 -0700 Subject: [PATCH 2/2] Keep existing behavior unchanged --- sling/sling/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sling/sling/__init__.py b/sling/sling/__init__.py index 62f15c3..a27993e 100644 --- a/sling/sling/__init__.py +++ b/sling/sling/__init__.py @@ -574,7 +574,7 @@ def stream(self, env:dict=None, stdin=None) -> Iterable[list]: # conform to legacy module Sling = Task -def _run(cmd: str, temp_file: str, return_output=False, print_output=True, env:dict=None, stdin=None): +def _run(cmd: str, temp_file: str, return_output=False, print_output=False, env:dict=None, stdin=None): """ Runs the task. @@ -591,6 +591,8 @@ def _run(cmd: str, temp_file: str, return_output=False, print_output=True, env:d for line in _exec_cmd(cmd, env=env, stdin=stdin): if return_output: lines.append(line) + else: + print(line, flush=True) if print_output: print(line, flush=True)