@@ -124,8 +124,8 @@ exec('my.bat', (err, stdout, stderr) => {
124
124
understand the ` -c ` switch on UNIX or ` /s /c ` on Windows. On Windows,
125
125
command line parsing should be compatible with ` cmd.exe ` .)
126
126
* ` 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 ` )
129
129
* ` killSignal ` {String} (Default: 'SIGTERM')
130
130
* ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
131
131
* ` 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
182
182
identified by the ` killSignal ` property (the default is ` 'SIGTERM' ` ) if the
183
183
child runs longer than ` timeout ` milliseconds.
184
184
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
-
189
185
* Note: Unlike the ` exec() ` POSIX system call, ` child_process.exec() ` does not
190
186
replace the existing process and uses a shell to execute the command.*
191
187
@@ -198,8 +194,8 @@ replace the existing process and uses a shell to execute the command.*
198
194
* ` env ` {Object} Environment key-value pairs
199
195
* ` encoding ` {String} (Default: 'utf8')
200
196
* ` 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)
203
199
* ` killSignal ` {String} (Default: 'SIGTERM')
204
200
* ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
205
201
* ` gid ` {Number} Sets the group identity of the process. (See setgid(2).)
@@ -533,18 +529,21 @@ configuration at startup.
533
529
* ` args ` {Array} List of string arguments
534
530
* ` options ` {Object}
535
531
* ` 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
537
534
- supplying this value will override ` stdio[0] `
538
535
* ` stdio ` {Array} Child's stdio configuration. (Default: 'pipe')
539
536
- ` stderr ` by default will be output to the parent process' stderr unless
540
537
` stdio ` is specified
541
538
* ` env ` {Object} Environment key-value pairs
542
539
* ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
543
540
* ` 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
548
547
* ` encoding ` {String} The encoding used for all stdio inputs and outputs. (Default: 'buffer')
549
548
* return: {Buffer|String} The stdout from the command
550
549
@@ -565,7 +564,8 @@ throw. The [`Error`][] object will contain the entire result from
565
564
* ` command ` {String} The command to run
566
565
* ` options ` {Object}
567
566
* ` 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
569
569
- supplying this value will override ` stdio[0] `
570
570
* ` stdio ` {Array} Child's stdio configuration. (Default: 'pipe')
571
571
- ` 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
577
577
command line parsing should be compatible with ` cmd.exe ` .)
578
578
* ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
579
579
* ` 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')
585
588
* return: {Buffer|String} The stdout from the command
586
589
587
590
The ` child_process.execSync() ` method is generally identical to
@@ -602,17 +605,21 @@ throw. The [`Error`][] object will contain the entire result from
602
605
* ` args ` {Array} List of string arguments
603
606
* ` options ` {Object}
604
607
* ` 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
606
610
- supplying this value will override ` stdio[0] `
607
611
* ` stdio ` {Array} Child's stdio configuration.
608
612
* ` env ` {Object} Environment key-value pairs
609
613
* ` uid ` {Number} Sets the user identity of the process. (See setuid(2).)
610
614
* ` 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')
616
623
* ` shell ` {Boolean|String} If ` true ` , runs ` command ` inside of a shell. Uses
617
624
'/bin/sh' on UNIX, and 'cmd.exe' on Windows. A different shell can be
618
625
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`
951
958
property becomes ` null ` . It is recommended not to use ` .maxConnections ` when
952
959
this occurs.
953
960
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 ` .*
955
963
956
964
### child.stderr
957
965
@@ -1029,6 +1037,19 @@ then this will be `undefined`.
1029
1037
` child.stdout ` is an alias for ` child.stdio[1] ` . Both properties will refer
1030
1038
to the same value.
1031
1039
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
+
1032
1053
[ `popen(3)` ] : http://linux.die.net/man/3/popen
1033
1054
[ `ChildProcess` ] : #child_process_child_process
1034
1055
[ `child_process.exec()` ] : #child_process_child_process_exec_command_options_callback
@@ -1048,3 +1069,4 @@ to the same value.
1048
1069
[ `stdio` ] : #child_process_options_stdio
1049
1070
[ synchronous counterparts ] : #child_process_synchronous_process_creation
1050
1071
[ `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