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

Cargo output could go to stderr #1473

Closed
huonw opened this issue Apr 1, 2015 · 15 comments · Fixed by #2693
Closed

Cargo output could go to stderr #1473

huonw opened this issue Apr 1, 2015 · 15 comments · Fixed by #2693
Labels
E-easy Experience: Easy

Comments

@huonw
Copy link
Member

huonw commented Apr 1, 2015

Currently output generated by cargo itself goes to stdout, while rustcs goes to stderr. This is pretty annoying for a command cargo run, where the user controls stdout and may not appreciate the contamination from cargo, e.g. cargo run --bin foo > some_file.txt will include the Compiling ... and Running ... lines.

Alteratively, I suppose we could support cargo run --output some_file.txt --bin foo which will do the redirect internally.

@alexcrichton
Copy link
Member

cc #653, a possible solution to the problem proposed there.

@alexcrichton
Copy link
Member

It does seem odd, though, to print informational output to stderr. Do other CLI tools have a habit of doing this?

@jethrogb
Copy link
Contributor

+1. I don't know about build et. al but the run output should really go to stderr, for the aforementioned reason of piping/redirecting output.

@kamalmarhubi
Copy link
Contributor

Having trouble thinking of tools that run a subcommand and also print informative output.

A data point for a similar use Bazel always sends its informational output to stderr, for whether for run, build, test or otherwise. This is particularly useful for bazel run.

A historical aside, stderr was originally introduced to make pipelines nice, allowing separation of "diagnostic" output from the main output. Source: Unix Reader section on PIPE.

@mxork
Copy link

mxork commented Mar 17, 2016

+1 for not contaminating stdout during a 'cargo run'

@kevincox
Copy link

Why does it seem strange to print diagnostic information to stderr? I generally think of stderr as the default place to print things, only using stdout for things that are actually output. This way shell piping works as expected.

Seeing as cargo output isn't supposed to be machine readable I would suggest putting all messages to stderr. This is especially useful when using cargo run as while cargo doesn't produce any "output" it is nice not to contaminate stdout in case the program you are running wants to use it for something.

@alexcrichton
Copy link
Member

This seems like a reasonable feature to me to add! Especially if it helps out running small scripts here and there so much.

@matklad
Copy link
Member

matklad commented May 9, 2016

I've tried implementing this. Looks like the only code change is in this line. There are several calls to shell.say(), shell.out() and println! left which rightfully print to stdout.

However when status messages go to stderr, 200+ of tests fail :( Should I just change with_stdout assertions to with_stderr, or is there perhaps a more intelligent and future proof way of testing this?

@alexcrichton
Copy link
Member

Yeah I had a feeling that this'd need a lot of updates to tests... We'd probably just want to update them to use with_stderr instead of with_stdout (as that's what we're testing)

@matklad
Copy link
Member

matklad commented May 10, 2016

Will try to send a PR later today :)

@w0rp
Copy link

w0rp commented Oct 26, 2017

Changing the output stream to stderr broke integration with ALE.

@w0rp
Copy link

w0rp commented Oct 26, 2017

Luckily, ALE can handle stderr, stdout, or both streams at the same time. ALE will have to accept both streams, because it could be either one, depending on the version of cargo.

@matklad
Copy link
Member

matklad commented Oct 26, 2017

Hm, the changed happened a rather long time ago, I would be surprised to find a lot of cargos which use stdout now....

@w0rp
Copy link

w0rp commented Oct 26, 2017

Yeah, I noticed that.

Strangely, I hadn't received any complaints until quite recently. That makes me wonder which versions of cargo people are actually using.

@matklad
Copy link
Member

matklad commented Oct 26, 2017

Hm, maybe then complaints are about some unrelated change to Cargo/Rustc output? It would be prudent to ask about the version of Cargo indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Experience: Easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants