Allow non-null standard output and/or error pipe to be passed to aio_subprocess_shell function

This commit is contained in:
Davte 2023-08-23 17:17:26 +02:00
parent eab81b065d
commit cf492f0c8b
Signed by: Davte
GPG Key ID: 70336F92E6814706
2 changed files with 9 additions and 4 deletions

View File

@ -11,7 +11,7 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it" __email__ = "davide@davte.it"
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
__license__ = "GNU General Public License v3.0" __license__ = "GNU General Public License v3.0"
__version__ = "2.9.4" __version__ = "2.9.5"
__maintainer__ = "Davide Testa" __maintainer__ = "Davide Testa"
__contact__ = "t.me/davte" __contact__ = "t.me/davte"

View File

@ -1713,16 +1713,21 @@ def recursive_dictionary_update(one: dict, other: dict) -> dict:
return one 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. """Run `command` in a subprocess shell.
Await for the subprocess to end and return standard error and output. Await for the subprocess to end and return standard error and output.
On error, log errors. 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: try:
_subprocess = await asyncio.create_subprocess_shell( _subprocess = await asyncio.create_subprocess_shell(
command command,
stdout=stdout,
stderr=stderr
) )
stdout, stderr = await _subprocess.communicate() stdout, stderr = await _subprocess.communicate()
if stdout: if stdout: