Home » Questions » Computers [ Ask a new question ]

Why did shell redirection fail?

Why did shell redirection fail?

The command causing the failure,

Asked by: Guest | Views: 49
Total answers/comments: 1
Guest [Entry]

"STDERR (standard error) in UNIX and UNIX-like systems is redirected using 2> instead of a single chevron (>).


gpc xxx.pas 2> error.txt

This will allow standard output (STDOUT) to be printed to the terminal like normal, but send all error messages to the file, error.txt.

If you want to collect both STDOUT and STDERR in the same file, use 2>&1: this tells the shell to copy STDERR (2) to STDOUT (1). Now redirecting STDOUT gets both streams:

gpc xxx.pas 2>&1 > stdout-and-stderr.txt"