1

I'm new to linux about ten days, and my English is not good. I'm learning the I/O redirection part.

I know when a command is successful, the screen do not display error message, and the command failed have one.

For example when I input cat file1. Before the command issued. What is the state of stdin, stdout and stderr? After I issued the command. What is the state of the standard stream?

When the file1 exist. In my opinion the final input is file1 and final output is the terminal.(not sure;-0-) And I don't have a error message. So does it mean that I don't have stderr here? Or where is it?

When there is no file exist. I have just a error message. So does it mean that I don't have stdin and redirect the stderr to stdout?

Thank you who can explain this to me or give me some clue like using man-page or anything else.

1 Answer 1

2

Under normal circumstances stdin, stdout, and stderr always exist:

ls -l /proc/self/fd

But not all of them are used by every command. You can check where a command writes to:

> strace -e trace=write cat nonexistfile
write(2, "cat: ", 5cat: )                    = 5
write(2, "nonexistfile", 12nonexistfile)            = 12
write(2, ": No such file or directory", 27: No such file or directory) = 27
write(2, "\n", 1
)                       = 1

Or simpler: compare

command >/dev/null

with

command 2>/dev/null
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .