简体   繁体   中英

What is the difference between error, stderr, stdout in node

I am using node.js and want to handle error messages. What are the differences between erro, stderr, stdout?

When scripting shell, I redirected stderr and found useful error message and it solved the problem.

I am not clear about the concept of what kind of outputs computer have either. Can anyone explain in a comprehensive way?

Thanks.

It is actually an interesting question. You would probably get more answers if you format the title of your question like this -- Node JS difference between error, stderr, and stdout.
I won't repeat the difference between stdout and stderr, as it is answered previously.

However, the difference between error and stderr is not that easily distinguished.

Error is an error object created by Node JS because it is having a problem executing your command. See more here

Stderr is a standard output stream that happens because something is wrong during execution -- that is Node JS has no trouble executing your command, it is your command itself throws the error.

Let me know if this is clear, otherwise, I'm happy to throw in an example:)

stderr and stdout are streams. Writing to console will log both streams. Apparently the distinction exists between them so we that if we want to (for example) redirect certain data elsewhere, we have the ability to be selective.

You may find the following article helpful.

http://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM