-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
child_process instance set encoding will trigger exception #18969
Comments
code
|
It's cp bug. I will raise a PR to fix it. |
@killagu Please see this, whether need bind listener on stdout and stderr when user not pass the callback param. The source code at: https://github.com/nodejs/node/blob/master/lib/child_process.js#L322-L358 |
@hstarorg It should in another issue. One pr resolve one problem. |
@killagu OK, Thanks. |
cp.exec decide to use `_stdout`(_stdout is string) or `Buffer.concat(_stdout)`(_stdout is buffer array) by options.encoding. but std(out|err) encoding can be changed. If encoding is changed to not null, `_stdout` will become string, and `Buffer.concat(_stdout)` will throw TypeError. This patch will fix it, use options.encoding and `std(out|err)._readableState.encoding`. Fixes: nodejs#18969
cp.exec decide to use `_stdout`(_stdout is string) or `Buffer.concat(_stdout)`(_stdout is buffer array) by options.encoding. but std(out|err) encoding can be changed. If encoding is changed to not null, `_stdout` will become string, and `Buffer.concat(_stdout)` will throw TypeError. This patch will fix it, use options.encoding and `std(out|err)._readableState.encoding`. PR-URL: #18976 Fixes: #18969 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Execute code at node command line.
The output is :
Is this a bug in nodejs?
BTW: The issue finder is @xqin
There didn't trigger the exception if use
cp.exec('pwd', {encoding: 'invalid'})
without the callback.@xqin has a new idea that whether need bind listener on
stdout
andstderr
when user not pass the callback param. The source code at: https://github.com/nodejs/node/blob/master/lib/child_process.js#L322-L358The text was updated successfully, but these errors were encountered: