@@ -124,8 +124,8 @@ exec('my.bat', (err, stdout, stderr) => {
124124 understand the ` -c ` switch on UNIX or ` /s /c ` on Windows. On Windows,
125125 command line parsing should be compatible with ` cmd.exe ` .)
126126 * ` timeout ` {Number} (Default: 0)
127- * ` maxBuffer ` {Number} largest amount of data (in bytes) allowed on stdout or
128- stderr - if exceeded child process is killed (Default: ` 200*1024 ` )
127+ * [ ` maxBuffer ` ] [ ] {Number} largest amount of data (in bytes) allowed on
128+ stdout or stderr - if exceeded child process is killed (Default: ` 200*1024 ` )
129129 * ` killSignal ` {String} (Default: 'SIGTERM')
130130 * ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
131131 * ` gid ` {Number} Sets the group identity of the process. (See setgid(2).)
@@ -182,10 +182,6 @@ If `timeout` is greater than `0`, the parent will send the the signal
182182identified by the ` killSignal ` property (the default is ` 'SIGTERM' ` ) if the
183183child runs longer than ` timeout ` milliseconds.
184184
185- The ` maxBuffer ` option specifies the largest amount of data (in bytes) allowed
186- on stdout or stderr - if this value is exceeded then the child process is
187- terminated.
188-
189185* Note: Unlike the ` exec() ` POSIX system call, ` child_process.exec() ` does not
190186replace the existing process and uses a shell to execute the command.*
191187
@@ -198,8 +194,8 @@ replace the existing process and uses a shell to execute the command.*
198194 * ` env ` {Object} Environment key-value pairs
199195 * ` encoding ` {String} (Default: 'utf8')
200196 * ` timeout ` {Number} (Default: 0)
201- * ` maxBuffer ` {Number} largest amount of data (in bytes) allowed on stdout or
202- stderr - if exceeded child process is killed (Default: 200\* 1024)
197+ * [ ` maxBuffer ` ] [ ] {Number} largest amount of data (in bytes) allowed on
198+ stdout or stderr - if exceeded child process is killed (Default: 200\* 1024)
203199 * ` killSignal ` {String} (Default: 'SIGTERM')
204200 * ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
205201 * ` gid ` {Number} Sets the group identity of the process. (See setgid(2).)
@@ -533,18 +529,21 @@ configuration at startup.
533529* ` args ` {Array} List of string arguments
534530* ` options ` {Object}
535531 * ` cwd ` {String} Current working directory of the child process
536- * ` input ` {String|Buffer} The value which will be passed as stdin to the spawned process
532+ * ` input ` {String|Buffer} The value which will be passed as stdin to the
533+ spawned process
537534 - supplying this value will override ` stdio[0] `
538535 * ` stdio ` {Array} Child's stdio configuration. (Default: 'pipe')
539536 - ` stderr ` by default will be output to the parent process' stderr unless
540537 ` stdio ` is specified
541538 * ` env ` {Object} Environment key-value pairs
542539 * ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
543540 * ` gid ` {Number} Sets the group identity of the process. (See setgid(2).)
544- * ` timeout ` {Number} In milliseconds the maximum amount of time the process is allowed to run. (Default: undefined)
545- * ` killSignal ` {String} The signal value to be used when the spawned process will be killed. (Default: 'SIGTERM')
546- * ` maxBuffer ` {Number} largest amount of data (in bytes) allowed on stdout or
547- stderr - if exceeded child process is killed
541+ * ` timeout ` {Number} In milliseconds the maximum amount of time the process
542+ is allowed to run. (Default: undefined)
543+ * ` killSignal ` {String} The signal value to be used when the spawned process
544+ will be killed. (Default: 'SIGTERM')
545+ * [ ` maxBuffer ` ] [ ] {Number} largest amount of data (in bytes) allowed on
546+ stdout or stderr - if exceeded child process is killed
548547 * ` encoding ` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
549548* return: {Buffer|String} The stdout from the command
550549
@@ -565,7 +564,8 @@ throw. The [`Error`][] object will contain the entire result from
565564* ` command ` {String} The command to run
566565* ` options ` {Object}
567566 * ` cwd ` {String} Current working directory of the child process
568- * ` input ` {String|Buffer} The value which will be passed as stdin to the spawned process
567+ * ` input ` {String|Buffer} The value which will be passed as stdin to the
568+ spawned process
569569 - supplying this value will override ` stdio[0] `
570570 * ` stdio ` {Array} Child's stdio configuration. (Default: 'pipe')
571571 - ` stderr ` by default will be output to the parent process' stderr unless
@@ -577,11 +577,14 @@ throw. The [`Error`][] object will contain the entire result from
577577 command line parsing should be compatible with ` cmd.exe ` .)
578578 * ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
579579 * ` gid ` {Number} Sets the group identity of the process. (See setgid(2).)
580- * ` timeout ` {Number} In milliseconds the maximum amount of time the process is allowed to run. (Default: undefined)
581- * ` killSignal ` {String} The signal value to be used when the spawned process will be killed. (Default: 'SIGTERM')
582- * ` maxBuffer ` {Number} largest amount of data (in bytes) allowed on stdout or
583- stderr - if exceeded child process is killed
584- * ` encoding ` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
580+ * ` timeout ` {Number} In milliseconds the maximum amount of time the process
581+ is allowed to run. (Default: undefined)
582+ * ` killSignal ` {String} The signal value to be used when the spawned process
583+ will be killed. (Default: 'SIGTERM')
584+ * [ ` maxBuffer ` ] [ ] {Number} largest amount of data (in bytes) allowed on
585+ stdout or stderr - if exceeded child process is killed
586+ * ` encoding ` {String} The encoding used for all stdio inputs and outputs.
587+ (Default: 'buffer')
585588* return: {Buffer|String} The stdout from the command
586589
587590The ` child_process.execSync() ` method is generally identical to
@@ -602,17 +605,21 @@ throw. The [`Error`][] object will contain the entire result from
602605* ` args ` {Array} List of string arguments
603606* ` options ` {Object}
604607 * ` cwd ` {String} Current working directory of the child process
605- * ` input ` {String|Buffer} The value which will be passed as stdin to the spawned process
608+ * ` input ` {String|Buffer} The value which will be passed as stdin to the
609+ spawned process
606610 - supplying this value will override ` stdio[0] `
607611 * ` stdio ` {Array} Child's stdio configuration.
608612 * ` env ` {Object} Environment key-value pairs
609613 * ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
610614 * ` gid ` {Number} Sets the group identity of the process. (See setgid(2).)
611- * ` timeout ` {Number} In milliseconds the maximum amount of time the process is allowed to run. (Default: undefined)
612- * ` killSignal ` {String} The signal value to be used when the spawned process will be killed. (Default: 'SIGTERM')
613- * ` maxBuffer ` {Number} largest amount of data (in bytes) allowed on stdout or
614- stderr - if exceeded child process is killed
615- * ` encoding ` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
615+ * ` timeout ` {Number} In milliseconds the maximum amount of time the process
616+ is allowed to run. (Default: undefined)
617+ * ` killSignal ` {String} The signal value to be used when the spawned process
618+ will be killed. (Default: 'SIGTERM')
619+ * [ ` maxBuffer ` ] [ ] {Number} largest amount of data (in bytes) allowed on
620+ stdout or stderr - if exceeded child process is killed
621+ * ` encoding ` {String} The encoding used for all stdio inputs and outputs.
622+ (Default: 'buffer')
616623 * ` shell ` {Boolean|String} If ` true ` , runs ` command ` inside of a shell. Uses
617624 '/bin/sh' on UNIX, and 'cmd.exe' on Windows. A different shell can be
618625 specified as a string. The shell should understand the ` -c ` switch on UNIX,
@@ -951,7 +958,8 @@ tracking when the socket is destroyed. To indicate this, the `.connections`
951958property becomes ` null ` . It is recommended not to use ` .maxConnections ` when
952959this occurs.
953960
954- * Note: this function uses [ ` JSON.stringify() ` ] [ ] internally to serialize the ` message ` .*
961+ * Note: this function uses [ ` JSON.stringify() ` ] [ ] internally to serialize the
962+ ` message ` .*
955963
956964### child.stderr
957965
@@ -1029,6 +1037,19 @@ then this will be `undefined`.
10291037` child.stdout ` is an alias for ` child.stdio[1] ` . Both properties will refer
10301038to the same value.
10311039
1040+ ## ` maxBuffer ` and Unicode
1041+
1042+ It is important to keep in mind that the ` maxBuffer ` option specifies the
1043+ largest number of * octets* allowed on ` stdout ` or ` stderr ` - if this value is
1044+ exceeded then the child process is terminated. This particularly impacts
1045+ output that includes multi-byte character encodings such as UTF-8 or UTF-16.
1046+ For instance, the following will output 13 UTF-8 encoded octets to ` stdout `
1047+ although there are only 4 characters:
1048+
1049+ ``` js
1050+ console .log (' 中文测试' );
1051+ ```
1052+
10321053[ `popen(3)` ] : http://linux.die.net/man/3/popen
10331054[ `ChildProcess` ] : #child_process_child_process
10341055[ `child_process.exec()` ] : #child_process_child_process_exec_command_options_callback
@@ -1048,3 +1069,4 @@ to the same value.
10481069[ `stdio` ] : #child_process_options_stdio
10491070[ synchronous counterparts ] : #child_process_synchronous_process_creation
10501071[ `JSON.stringify()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
1072+ [ `maxBuffer` ] : #child_process_maxbuffer_and_unicode
0 commit comments