mirror of
https://codeberg.org/privacy1st/exec-notify
synced 2024-12-22 23:16:04 +01:00
23 lines
591 B
Python
23 lines
591 B
Python
|
from typing import List
|
||
|
import sys
|
||
|
import subprocess
|
||
|
|
||
|
|
||
|
def execute(command: List[str]):
|
||
|
"""
|
||
|
Run the given command in a subprocess and pass stdin (if given) to that process.
|
||
|
Wait for command to complete.
|
||
|
|
||
|
:param command: A command to executed as list of words, e.g. ["echo", "hello"]
|
||
|
:return: (status, stdout, stderr)
|
||
|
"""
|
||
|
|
||
|
completed: subprocess.CompletedProcess = subprocess.run(
|
||
|
command,
|
||
|
stdin=sys.stdin,
|
||
|
capture_output=True,
|
||
|
check=False,
|
||
|
text=True
|
||
|
)
|
||
|
return completed.returncode, completed.stdout, completed.stderr
|