codekingpro/portable-devtools
114k
1from __future__ import annotations2 3import subprocess4 5CREATE_NO_WINDOW = 0x800000006 7 8def run_cmd(cmd):9 try:10 process = subprocess.Popen(11 cmd, # noqa: S60312 universal_newlines=True,13 stdin=subprocess.PIPE,14 stderr=subprocess.PIPE,15 stdout=subprocess.PIPE,16 encoding="utf-8",17 )18 out, err = process.communicate() # input disabled19 code = process.returncode20 except OSError as error:21 code, out, err = error.errno, "", error.strerror22 if code == 2 and "file" in err: # noqa: PLR200423 err = str(error) # FileNotFoundError in Python >= 3.324 return code, out, err25 26 27__all__ = (28 "CREATE_NO_WINDOW",29 "run_cmd",30)31 