exec-notify/execNotifyDir/exec.py

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