-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process.stdout is not detected as writable when redirecting output to a file #5
Comments
Same thing happens on Ubuntu: kiril@ubuntu:~/Downloads$ node -v
v4.2.6
kiril@ubuntu:~/Downloads$ cat repro.js
var isStream = require('is-stream');
console.log('is writable:', isStream.writable(process.stdout));
kiril@ubuntu:~/Downloads$ node repro.js
is writable: true
kiril@ubuntu:~/Downloads$ node repro.js > file.log
kiril@ubuntu:~/Downloads$ cat file.log
is writable: false
kiril@ubuntu:~/Downloads$ |
Hmm, weird, it changes to a different kind of stream when piped: var isStream = require('is-stream');
console.log(process.stdout);
console.log('is writable:', isStream.writable(process.stdout));
A temporary workaround could be to do a @silverwind @jasnell Do you think it makes sense to change it to inherit from WritableStream instead? |
To be honest, I'm not sure. @mcollina ... what do you think? |
So, this is extremely complex, and a duplicate of pinojs/pino#85 pinojs/pino#86. From node.js docs, a stream is cc @mafintosh |
I had considered doing an MR to special case |
@catdad SyncWriteStream is internal to Node, and only used in one place: https://github.com/nodejs/node/blob/dc7277909b0d842ea3f559628d6d7c7887bfd05b/lib/internal/process/stdio.js#L149. |
Yeah, in fact we've started the process of moving |
@mcollina, that's unfortunately only kind of true. It's intended to be internal, but it is definitely public, I can definitely create one, and it definitely works as I would expect it to work. So at least to me, that seems like something I have to consider as possible for a stream library to handle. |
@mcollina @jasnell Since this is sort of coming up now, I and many of the people I work with consider the Node documentation to be sparse and often missing information, so we regularly read the Node source code in order to work with various of the deeper APIs. It's very commonplace in my dev community to read the source code of open-source projects we use. |
Understood. In the case of |
In my opinion, the public API is the "reference", meaning that if it is not there you are relying on a behavior that a) is not covered by Node.js tests and b) can change at any time, without any notice. anyway, That thing is mainly used within the debug module https://github.com/visionmedia/debug/blob/39ecd87bcc145de5ca1cbea1bf4caed02c34d30a/node.js#L164. debug lifts some chunks of code straight from core. |
😉 This is the original bug that led me here: catdad/grandma#96 In this case, when writing to terminal, all is well. I would argue that |
LOL, I meant the current behavior is correct.
The bug is in core. It is documented as being a |
Closing as this was fixed in Node.js core: nodejs/node#8828 |
Sample code:
I have so far only tested this on Windows, here's the output of that test:
When running from the command line, everything is fine and it reports as
true
. However, when I redirect the same command line to a file, it reports asfalse
. When I checked, both_write
and_writableState
are undefined. But, of course, you can see that writing to stdout still works and redirects to the file, sinceconsole.log
works just fine.The text was updated successfully, but these errors were encountered: