Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stderr argument in Conanfile's run method docs #3482

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion reference/conanfile/running_and_output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Running commands

.. code-block:: python

run(self, command, stdout=None, cwd=None, ignore_errors=False, env="", quiet=False, shell=True, scope="build")
run(self, command, stdout=None, cwd=None, ignore_errors=False, env="", quiet=False, shell=True, scope="build", stderr=None)
Copy link
Contributor

@czoido czoido Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't have any code snippet to show how to capture the stdout or stderr in the recipe, maybe this would be a good opportunity to add some code to explain how to capture the output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Good idea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please check



``self.run()`` is a helper to run system commands while injecting the calls to activate the appropriate environment,
Expand All @@ -49,3 +49,13 @@ It also wraps the commands with the results of the :ref:`command wrapper plugin<

* ``command`` should be specified as a string which is passed to the system shell.
* When the argument ``quiet`` is set to true, the invocation of ``self.run()`` will not print the command to be executed.

Use the ``stdout`` and ``stderr`` arguments to redirect the output of the command to a file-like object instead of the console.

.. code-block:: python

# Redirect stdout to a file
with open("ninja_stdout.log", "w") as stdout:
# Redirect stderr to a StringIO object to be able to read it later
stderr = StringIO()
self.run("ninja ...", stdout=stdout, stderr=stderr)