Question

I am a beginner to Linux console and start write some code in C.

I try to compile code and hope to see messages using command

gcc foo.c -o foo -v | less

But the result text cannot be paged. Any wrong I do? Thanks.

Was it helpful?

Solution

The | pipe command just redirects stdout. To redirect stderr as well as stdout use |&:

gcc foo.c -o foo -v |& less

OTHER TIPS

The error messages from gcc are going to stderr, and your pipe is only catching stdout.

Assuming that you're using bash, try this to capture stderr as well as stdout:

gcc foo.c -o foo -v 2>&1 | less

GCC's warnings are printed to stderr, not stdout. You'd have to redirect that too:

gcc foo.c -o foo -v |& less
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top