2022-08-01 16:30:29 +00:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
2022-08-02 02:22:41 +00:00
|
|
|
from typing import Tuple
|
2022-08-01 10:31:48 +00:00
|
|
|
|
2022-08-03 04:26:50 +00:00
|
|
|
|
2022-08-01 16:30:29 +00:00
|
|
|
def execute_and_return(command_string: str) -> Tuple[str, str]:
|
|
|
|
def _decode(subprocess_err_out_tuple):
|
|
|
|
return tuple(
|
|
|
|
to_decode.decode("UTF-8").strip()
|
|
|
|
for to_decode in subprocess_err_out_tuple
|
|
|
|
)
|
|
|
|
|
|
|
|
def execute_and_return_decoded_std_streams(command_string):
|
|
|
|
return _decode(
|
|
|
|
subprocess.Popen(
|
|
|
|
shlex.split(command_string),
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
).communicate()
|
|
|
|
)
|
|
|
|
|
2022-08-02 02:22:41 +00:00
|
|
|
std_out, std_err = execute_and_return_decoded_std_streams(command_string)
|
2022-08-01 16:30:29 +00:00
|
|
|
return std_out, std_err
|