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

When time command is given data on stdin, it either prints the man page for time or doesn't notice non-zero subprocess exit or show stderr #8841

Closed
terrycojones opened this issue Mar 29, 2022 · 4 comments
Labels

Comments

@terrycojones
Copy link

fish version 3.4.1 on OS X 12.2.1

If I run yes | time cat lkslkjlklkslsj (where the file passed to cat is non-existent), I get a prompt back immediately, nothing appears on standard error, and the exit status ($status) is 2. The same thing happens if I run e.g., cat /etc/passwd | time cat lkslkjlk. When I do the same thing without time I get the expected message about a non-existent file on standard error from the cat and the exit status is 1. So it appears time has detected the non-zero exit status but suppressed the standard error output and it exits with 2.

Bizarrely, if I run echo hi | time cat lskjlsjsjlskjlskj, fish displays what I see when I run man time (including piping it to what seems to be more (not less which is what I have $PAGER set to))! Maybe because these are both builtin commands fish does something unexpected (at least to me).

@faho
Copy link
Member

faho commented Mar 29, 2022

time is a decorator for the entire pipeline.

You need time yes | cat. Same thing applies to not.

@faho faho added the question label Mar 29, 2022
@terrycojones
Copy link
Author

Hi @faho - thanks for this explanation.

I would suggest (though I don't know who to) that time should not have the current behaviour if stdin is not a tty. It's obviously wrong for a fish user to do what I did (though the man page gives no indication of this, and the fish behaviour is not the behaviour of /usr/bin/time (which passes on the stdin and also prints the stderr of a failing command). So accepting that the fish version of time is going to behave as it does, it seems like it would be a good idea for it to tell you when you've made this error. Silently dropping the stderr output of the failing command seems quite wrong.

Anyway, I'm not sure who I should be saying this to, if anyone! Thanks again for the reply.

@ridiculousfish
Copy link
Member

I added an error message for when time is used in a pipeline.

@terrycojones
Copy link
Author

Great - thanks!

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

No branches or pull requests

3 participants