From cf492f0c8b8938b1fcf5b06a2ac6a8b2f7c910d7 Mon Sep 17 00:00:00 2001 From: Davte Date: Wed, 23 Aug 2023 17:17:26 +0200 Subject: [PATCH] Allow non-null standard output and/or error pipe to be passed to aio_subprocess_shell function --- davtelepot/__init__.py | 2 +- davtelepot/utilities.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index f1e2b45..3cb3f1c 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -11,7 +11,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.9.4" +__version__ = "2.9.5" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/utilities.py b/davtelepot/utilities.py index ad5773e..f2a9605 100644 --- a/davtelepot/utilities.py +++ b/davtelepot/utilities.py @@ -1713,16 +1713,21 @@ def recursive_dictionary_update(one: dict, other: dict) -> dict: return one -async def aio_subprocess_shell(command: str) -> Tuple[str, str]: +async def aio_subprocess_shell(command: str, + stdout=None, + stderr=None) -> Tuple[str, str]: """Run `command` in a subprocess shell. Await for the subprocess to end and return standard error and output. On error, log errors. + If `stdout` and/or `stderr` are given, use them as output and/or error pipes. + Example of non-null standard output/error pipe: asyncio.subprocess.PIPE """ - stdout, stderr = None, None try: _subprocess = await asyncio.create_subprocess_shell( - command + command, + stdout=stdout, + stderr=stderr ) stdout, stderr = await _subprocess.communicate() if stdout: