DEV Community

Omar Dulaimi
Omar Dulaimi

Posted on • Edited on

What are 𝗳𝗢𝗹𝗲 π—±π—²π˜€π—°π—Ώπ—Άπ—½π˜π—Όπ—Ώπ˜€ in π—‘π—Όπ—±π—²π—·π˜€?

What are 𝗳𝗢𝗹𝗲 π—±π—²π˜€π—°π—Ώπ—Άπ—½π˜π—Όπ—Ώπ˜€ in π—‘π—Όπ—±π—²π—·π˜€?

In my last post we talked about all the different ways you can write stuff out to the standard output, and we touched upon the file system method π˜„π—Ώπ—Άπ˜π—²π—¦π˜†π—»π—°.

Today we talk a little bit more about it's first argument, and what it really means under the hood.

The 1st arg is a 𝗳𝗢𝗹𝗲 π—±π—²π˜€π—°π—Ώπ—Άπ—½π˜π—Όπ—Ώ, basically a unique identifier(unsigned integer) that represents a file or other input/output source like a pipe or a network socket. Negative values are reserved for error conditions and "no value".

Each Unix process should have the three file descriptors mentioned in the snap below. Which they correspond to the standard streams; π—½π—Ώπ—Όπ—°π—²π˜€π˜€.π˜€π˜π—±π—Όπ˜‚π˜, π—½π—Ώπ—Όπ—°π—²π˜€π˜€.π˜€π˜π—±π—Άπ—» and π—½π—Ώπ—Όπ—°π—²π˜€π˜€.π˜€π˜π—±π—²π—Ώπ—Ώ.

To avoid hardcoding these integers in your code, instead use the values provided by π—‘π—Όπ—±π—²π—·π˜€:

0 => process.stdin.fd
1 => process.stdout.fd
2 => process.stderr.fd

Did you learn something new today?

Like and share this post, and follow me for more!

filedes

Top comments (0)