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!
Top comments (0)