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

[question] stdout/stderr confusion #17412

Closed
1 task done
walterschneider opened this issue Dec 4, 2024 · 3 comments
Closed
1 task done

[question] stdout/stderr confusion #17412

walterschneider opened this issue Dec 4, 2024 · 3 comments
Assignees

Comments

@walterschneider
Copy link

walterschneider commented Dec 4, 2024

What is your question?

Hi!
I am confused regarding the stdout and stderr streams:

conan_run
All processes started with conan_run redirect stdout to stderr,
the docu says "Instead of print to sys.stdout print to that stream" but it is initialized with sys.stderr.
A typo?
However, i can control the streams with the stderr option.

ConanOutput
All messages (info, warning, error) are written to stderr.
In my opinion, this should be stdout for info and stderr for error and popably warning.

Can you explain the background?
Thank you.

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@czoido czoido self-assigned this Dec 4, 2024
@czoido
Copy link
Contributor

czoido commented Dec 4, 2024

Hi @walterschneider,

Thanks a lot for the question.

For the first part, yes, that seems a typo in the conan_run docstring but please, be aware that conan_run is not meant to be public and be used outside the internal code for Conan. To run external commands in recipes please use Conanfile's run method, like explained in the docs: https://docs.conan.io/2/reference/conanfile/running_and_output.html

Regarding ConanOutput, the the decision to send all messages, but the final output of the command, including info, warnings, and errors, to stderr follows a deliberate design choice that aligns with common practices in many CLI tools and the POSIX standard (you'll see that it defines standard output (for writing conventional output) and standard error (for writing diagnostic output) so stderr is not only used for errors but all kinds of informative messages).

For Conan, the separation allows the main data output of commands to be cleanly directed to stdout, while diagnostic and auxiliary information (like logs, progress bars, and status messages) is sent to stderr.

For example, if you're running a command like conan install and want to capture its main output in a file (e.g., in JSON format), you can redirect stdout to a file without mixing it with diagnostic messages. This approach is used by many well-known tools like git, curl, wget, rsync, and others.

Hope this helps, please don't hesitate to reach out if you have any further questions or need additional clarification!

@walterschneider
Copy link
Author

Thank you very much for your fast end detailed explanation!
I am using use ConanFile.run which forwards to conan_run.

@memsharded
Copy link
Member

#17507 adds a new --output-file to enforce writing the result in that file irrespective of the stdout redirections or other possible issues. It will be in next Conan 2.12. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants