Repository navigation
child_process instance set encoding will trigger exception #18969
Copy link
Copy link
Closed
Labels
child_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.
Description
Activity
$ node -v v9.3.0 $ uname -a Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64code
$ cat test.js const cp = require('child_process'); const child = cp.exec('pwd', {encoding: 'invalid'}, (err, stdout, stderr) => { console.log('callback', err) console.log('callback', typeof stdout, stdout) }) child.stdout.setEncoding('utf8') child.stdout.on('data', function (v) { console.log(typeof v, v) }) $ node test.js string /Users/xqin buffer.js:475 throw new errors.TypeError( ^ TypeError [ERR_INVALID_ARG_TYPE]: The "list" argument must be one of type Array, Buffer, or Uint8Array at Function.concat (buffer.js:475:13) at ChildProcess.exithandler (child_process.js:259:23) at ChildProcess.emit (events.js:159:13) at maybeClose (internal/child_process.js:943:16) at Socket.stream.socket.on (internal/child_process.js:363:11) at Socket.emit (events.js:159:13) at Pipe._handle.close [as _onclose] (net.js:568:12)- addedchild_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.
on Feb 24, 2018 It's cp bug.
cp have not checked the stdout or stderr encoding changed, cp decide by options.encoding to use stdout orBuffer.concatit.when encoding change to utf-8, theBuffer.concatwill failed.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.
- added a commit that references this issue
on May 2, 2018 - added a commit that references this issue
on May 18, 2018 - added a commit that references this issue
on May 22, 2018
Metadata
Metadata
Assignees
Labels
child_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.
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
stdoutandstderrwhen user not pass the callback param. The source code at: https://github.com/nodejs/node/blob/master/lib/child_process.js#L322-L358