-
Notifications
You must be signed in to change notification settings - Fork 7.3k
stdout not flushed upon exit with output redirect #1669
Comments
You can force it to flush like this: var flushed = process.stdout.flush()
if (!flushed) process.once("drain", function () {
process.exit(0)
}) However, pending data on the stdout socket should prevent an exit, so this is a bug. |
Thanks, I'll use that as a workaround. |
Looks like flush() was removed in the latest Node. Is there another way to force the flush now? |
Flush was unofficial/undocumented, sorry. Nicholas would you be able to provide an atomic testcase of your large data case to reproduce this bug. Then we can get a patch in. Thanks |
Hey, travelling at the moment so don't have time to whip a standalone demo up. If you try installing [email protected] and run it on the demo file (https://github.com/stubbornella/csslint/blob/master/demos/demo.css), then try to capture the output, you'll end up with an empty file. CSS Lint also has tagged versions in source control, so you could pull the v0.5.0 tag from GitHub and get the source locally as well. |
That may be, but as nzakas already asked, is there any way to control flushing now? stdout/stderr were made unbuffered for TTY's and files, but not for pipes. I have an application that uses pipes and it's surprising that node 0.6.x is now suddenly a regression for that use case, because there's no way to ensure data is actually flushed as soon as possible. Using writeSync seems to have the wanted behavior, but there is nothing in the documentation saying this will ensure a stdout flush (IIRC standard Unix behavior is to flush when there's a newline for text mode, or something?), so I'd appreciate a definite word on this. |
Here is a simple test to see if its (not) working. For me (node v0.4.12) its not working correctly. |
I hit this issue too, and can reproduce it with ichernev's test case from the last comment on node 0.5.5pre. When output is redirected, nothing is written, but when it is not redirected, things are printed out properly. |
FWIW, I've worked around this in my own code with the super-hacky: process.stdout = process.stderr; But since I'm developing a CLI tool that might have its output piped, this is less than ideal. +1 for a fix! |
Is this still an issue? I just tried @ichernev's example in v0.6.9 and don't see any issues. |
Yep, v0.6.8 works for me too. |
This is still an issue in v0.8.12 for Windows 7 64-bit. I'm working around this by exiting on the 'drain' event and writing empty string to the stream. I write the empty string to the stream in case there is nothing more to 'drain' by the time I'm registering for the event:
|
@mpareja Can you open a new issue for that? Please include a test case. Thanks. |
Same error with mocha called from webstorm console. I thought the problem is with webstorm because from git bash I got the whole error stack in the console. Strange behavior... :S I got this in webstorm console: Hmm it depends only on how long I have to wait for the response. So I think it could be a timeout problem, not necessarily this bug. |
this is a real problem. mocha uses console.log to log errors. but error stack traces on windows are reproducible not redirected to a file or other process while the actual errors are. node.js should make sure console.log output is flushed before the process is exited. |
Added a 'windows' label. This shouldn't be an issue any longer on Unices. |
should the ticket not be reopened then ? |
I should have created a new issue. Sorry folks, life's been crazy and I haven't done this. I'll open a ticket with a repro sample at some point soon and reference it from this issue. |
is this reason for gruntjs/grunt#504 |
ah the issue is #3584 |
…ffer is not flushed at process exit and console.log()s performed by the application might not get printed. Fixes emscripten-core#2582
… fix other.test_warn_undefined on Windows. The end of the output buffer would not get printed during the test, which would cause the test to fail. See also #2582
Using Node.js v0.4.10 on Ubuntu.
If I write a large amount of data to stdout, either via console.log() or process.stdout.write(), and then try to redirect the output to a file, the file remains empty even though the output never appears in the console. I'm not forcing the process to exit, it's completing its task and then exiting on its own. I expected stdout to flush at this point, but it appears not to.
This behavior can be seen with CSS Lint v0.5.0
I tried working around this by using:
However, this is causing other errors.
Is this behavior expected? If so, how can I ensure stdout is flushed so that output can be captured as usual?
The text was updated successfully, but these errors were encountered: