-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Support '/dev/stdout' as a valid '--out' parameter #5454
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
Conversation
process.stdout.write(data, "utf8"); | ||
} | ||
else { | ||
_fs.writeFileSync(fileName, data, "utf8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is fs.writeFileSync not sufficient here? what can we change to make it work for all cases without the special handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhegazy: Not using fs.writeFileSync
is at least currently required for supporting output to stdout. With fs.writeFileSync
, if you target /dev/stdout
, as previously stated, you get error 'ESPIPE, invalid seek' on Linux and 'ENXIO, no such device or address' on OS X.
what can we change to make it work for all cases without the special handling?
Talk to the Node.js team to investigate why writing to /dev/stdout
with fs.writeFileSync
doesn't work and/or convince them to change / fix it.
Conversely: What problems do you see with this proposed approach to special-casing stdout output?
After all, note that @MartyIX's quote from the Node.js documentation implies that stdout and stderr are special:
process.stderr and process.stdout are unlike other streams in Node.js [...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhegazy @mklement0 I tried to analyze why node returns ESPIPE, invalid seek
so I cloned the node repo from Github, compiled it and run:
$ echo "require('fs').writeFileSync('/dev/stdout', 'hello');" | ./node
fs.js:707
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: ESPIPE: invalid seek, write
at Error (native)
at Object.fs.writeSync (fs.js:707:20)
at Object.fs.writeFileSync (fs.js:1235:24)
at [stdin]:1:15
at Object.exports.runInThisContext (vm.js:54:17)
at Object.<anonymous> ([stdin]-wrapper:6:22)
at Module._compile (module.js:425:26)
at node.js:589:27
at doNTCallback0 (node.js:430:9)
at process._tickCallback (node.js:359:13)
So we have the line with binding.writeBuffer
where parameter values are 11 <Buffer 68 65 6c 6c 6f> 0 5 0
(I simply used console.log()
to output parameter values).
binding.writeBuffer
call leads to calling SYNC_CALL(write, nullptr, fd, &uvbuf, 1, pos)
and this command throws an exception (a debug statement of mine after this call is not printed). SYNC_CALL(write, ...)
leads to calling uv_fs_write
function and it finishes. I don't know where exactly is the exception thrown (it's not in SYNC_DEST_CALL
).
To make a conclusion, the problem seems to be in the fact that fs.writeFileSync
uses a buffer implementation which sets offset value 0
for writing to a file (it is stdout in our case). However, this is inconclusive because I don't know Node architecture and my knowledge of C++ is fairly basic.
@DanielRosenwasser You are right. This seems to work:
|
The behavior with the latest commit is:
|
@MartyIX :) So just adding @DanielRosenwasser: By saying that it's not necessarily cross-platform, are you just referring to the |
@mklement0 I think so, yes. I think that Daniel simply does not want to handle special cases because it's typically hard to do all the conventions right for all platforms. If one can come up with a solution without special handling, it also means that it will be easier to maintain it in future. My point here is not that "it's too much work, we won't do it". Anyway, that's only my interpretation and my understanding. |
@MartyIX: Understood. Come to think of it, it is the So the use of That brings us back to Using As it stands (just to summarize), your proposed PR would only benefit Unix users that use literal target
|
@mklement0 I agree with you. I like the former solution better than the current one too. Yet, any accepted patch is better than none from my point of view because the current behavior of |
Understood. Your patch is worth applying in any event, because it also fixes the inability to write to other kinds of special files, such as FIFOs (though that may be a more exotic use case). And kudos for figuring out the issue with Ceterum censeo "-" esse implementam. |
I was referring to Glad to hear the fix worked @MartyIX. Dealing with general file descriptors is the right way to handle it, so I think this is the appropriate fix. I'll test it out in a bit. I'm not totally against allowing |
@DanielRosenwasser: Glad to hear that |
So this doesn't work when you request non-inline sourcemaps, but that's not a big deal. Can you wrap the change in a Basically, initialize the file descriptor to |
@DanielRosenwasser Sure |
Support '/dev/stdout' as a valid '--out' parameter
Thanks @MartyIX! |
Proposed fix for issue #4841.
I have updated
writeFile
function for Node system. Essentially, I've ended with the code that @mklement0 suggested in his comment. The documentation states that:The new behavior can be tested this way:
Can you comment on a proper way of testing this feature?
Thanks!
I don't know how WScript system works and if the issue is present there too or not.