3

I'd like ANSI C style stdout operations on stdout.

That is, I'd like to be able to treat a file descriptor and stdout in exactly the same way.

1 Answer 1

12

One can use fs.read to read from a file descriptor and fs.write to write to a file descriptor.

Since process.stdout is a Stream it has a property fd which refers to the file descriptor.

fs.write(process.stdout.fd, new Buffer("hello world"), 0, 11, 0)

Note that the fd property is undocumented and might disappear in later versions of node.

Since this isn't documented anywhere you basically have to read the source

Sign up to request clarification or add additional context in comments.

1 Comment

The process.std***.fd properties are documented nowadays. TypeScript doesn't know about that though, so it's useful to know the fd of stdout is always 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.