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

Comments

Projects
None yet
8 participants
@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

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 2, 2015

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

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 2, 2015

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

@jethrogb

This comment has been minimized.

Copy link
Contributor

jethrogb commented Jan 28, 2016

+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

This comment has been minimized.

Copy link
Contributor

kamalmarhubi commented Jan 28, 2016

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

This comment has been minimized.

Copy link

mxork commented Mar 17, 2016

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

@kevincox

This comment has been minimized.

Copy link

kevincox commented Mar 20, 2016

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

This comment has been minimized.

Copy link
Member

alexcrichton commented Mar 21, 2016

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

@matklad

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

alexcrichton commented May 10, 2016

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

This comment has been minimized.

Copy link
Member

matklad commented May 10, 2016

Will try to send a PR later today :)

@w0rp

This comment has been minimized.

Copy link

w0rp commented Oct 26, 2017

Changing the output stream to stderr broke integration with ALE.

@w0rp

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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
You can’t perform that action at this time.