From f64e5f55b5ba39c1f89b0841d6b0d8ab1dc8504b Mon Sep 17 00:00:00 2001 From: Yu-Ting Hsiung Date: Wed, 4 Feb 2026 15:03:33 +0800 Subject: [PATCH] refactor(cmd): replace subprocess.Popen with run --- commitizen/cmd.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/commitizen/cmd.py b/commitizen/cmd.py index fe70da9c9b..065c99a1e9 100644 --- a/commitizen/cmd.py +++ b/commitizen/cmd.py @@ -38,20 +38,11 @@ def _try_decode(bytes_: bytes) -> str: def run(cmd: str, env: Mapping[str, str] | None = None) -> Command: if env is not None: env = {**os.environ, **env} - process = subprocess.Popen( - cmd, - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - stdin=subprocess.PIPE, - env=env, - ) - stdout, stderr = process.communicate() - return_code = process.returncode + c = subprocess.run([cmd], shell=True, capture_output=True, env=env) return Command( - _try_decode(stdout), - _try_decode(stderr), - stdout, - stderr, - return_code, + _try_decode(c.stdout), + _try_decode(c.stderr), + c.stdout, + c.stderr, + c.returncode, )