diff --git a/conans/model/conan_file.py b/conans/model/conan_file.py index d480d37fc7c..c2d009575f8 100644 --- a/conans/model/conan_file.py +++ b/conans/model/conan_file.py @@ -318,7 +318,7 @@ def generators_path(self) -> Path: return Path(self.generators_folder) def run(self, command, stdout=None, cwd=None, ignore_errors=False, env="", quiet=False, - shell=True, scope="build"): + shell=True, scope="build", stderr=None): # NOTE: "self.win_bash" is the new parameter "win_bash" for Conan 2.0 command = self._conan_helpers.cmd_wrapper.wrap(command, conanfile=self) if env == "": # This default allows not breaking for users with ``env=None`` indicating @@ -332,7 +332,7 @@ def run(self, command, stdout=None, cwd=None, ignore_errors=False, env="", quiet from conans.util.runners import conan_run if not quiet: ConanOutput().writeln(f"{self.display_name}: RUN: {command}", fg=Color.BRIGHT_BLUE) - retcode = conan_run(wrapped_cmd, cwd=cwd, stdout=stdout, shell=shell) + retcode = conan_run(wrapped_cmd, cwd=cwd, stdout=stdout, stderr=stderr, shell=shell) if not quiet: ConanOutput().writeln("") diff --git a/conans/test/functional/conanfile/runner_test.py b/conans/test/functional/conanfile/runner_test.py index 9144dc4596b..c4180f2aef7 100644 --- a/conans/test/functional/conanfile/runner_test.py +++ b/conans/test/functional/conanfile/runner_test.py @@ -56,3 +56,18 @@ def source(self): client.save({"conanfile.py": conanfile}) client.run("source .") self.assertIn('conanfile.py: Buffer got msgs Hello', client.out) + + def test_custom_stream_stderr(self): + conanfile = textwrap.dedent(""" + from io import StringIO + from conan import ConanFile + class Pkg(ConanFile): + def source(self): + my_buf = StringIO() + self.run('echo Hello 1>&2', stderr=my_buf) + self.output.info("Buffer got stderr msgs {}".format(my_buf.getvalue())) + """) + client = TestClient() + client.save({"conanfile.py": conanfile}) + client.run("source .") + self.assertIn('conanfile.py: Buffer got stderr msgs Hello', client.out)