Reputation: 2050
as far as i learned in programming, when i want to add the input redirection to my program, i write my program as when it executed, it waits for the user's input (with std::cin or something similar). but i got confused by less command.
We all know that we can do something like this:
ls -la | less
but when we try to execute
less
without any arguments we get an error. how come ?!
Upvotes: 2
Views: 685
Reputation: 213568
The less
accepts input from stdin or from a file.
Since it doesn't make sense to accept input from a terminal (just to display the same input back to a terminal), the less
program probably checks if stdin is a terminal (with isatty
) and refuses to run.
See man 3 isatty
Upvotes: 5
Reputation: 361869
Less is a pager, a UNIX term for a program that shows output one screenful at a time. If you pipe a program's output to less, it shows the output one page a time. If you pass file names on the command line, it shows those files page by page.
If you do neither, there's nothing to page through. It throws an error because there's nothing sensible it can do. What do you want it to show?
Upvotes: 2