diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 562c7751b14..505691d7fc2 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1476,7 +1476,14 @@ def run_pip(self, *args: str, **kwargs: Any) -> int | str: def run_python_script(self, content: str, **kwargs: Any) -> int | str: return self.run( - self._executable, "-I", "-W", "ignore", "-", input_=content, **kwargs + self._executable, + "-I", + "-W", + "ignore", + "-", + input_=content, + stderr=subprocess.DEVNULL, + **kwargs, ) def _run(self, cmd: list[str], **kwargs: Any) -> int | str: @@ -1486,6 +1493,7 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: call = kwargs.pop("call", False) input_ = kwargs.pop("input_", None) env = kwargs.pop("env", dict(os.environ)) + stderr = kwargs.pop("stderr", subprocess.STDOUT) try: if self._is_windows: @@ -1501,18 +1509,16 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: output = subprocess.run( command, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=stderr, input=encode(input_), check=True, **kwargs, ).stdout elif call: - return subprocess.call( - command, stderr=subprocess.STDOUT, env=env, **kwargs - ) + return subprocess.call(command, stderr=stderr, env=env, **kwargs) else: output = subprocess.check_output( - command, stderr=subprocess.STDOUT, env=env, **kwargs + command, stderr=stderr, env=env, **kwargs ) except CalledProcessError as e: raise EnvCommandError(e, input=input_)