@@ -214,6 +214,23 @@ child runs longer than `timeout` milliseconds.
214
214
* Note: Unlike the exec(3) POSIX system call, ` child_process.exec() ` does not
215
215
replace the existing process and uses a shell to execute the command.*
216
216
217
+ If this method is invoked as its [ ` util.promisify() ` ] [ ] ed version, it returns
218
+ a Promise for an object with ` stdout ` and ` stderr ` properties.
219
+
220
+ For example:
221
+
222
+ ``` js
223
+ const util = require (' util' );
224
+ const exec = util .promisify (require (' child_process' ).exec );
225
+
226
+ async function lsExample () {
227
+ const {stdout , stderr } = await exec (' ls' );
228
+ console .log (' stdout:' , stdout);
229
+ console .log (' stderr:' , stderr);
230
+ }
231
+ lsExample ();
232
+ ```
233
+
217
234
### child_process.execFile(file[ , args] [ , options ] [ , callback] )
218
235
<!-- YAML
219
236
added: v0.1.91
@@ -263,6 +280,19 @@ can be used to specify the character encoding used to decode the stdout and
263
280
stderr output. If ` encoding ` is ` 'buffer' ` , or an unrecognized character
264
281
encoding, ` Buffer ` objects will be passed to the callback instead.
265
282
283
+ If this method is invoked as its [ ` util.promisify() ` ] [ ] ed version, it returns
284
+ a Promise for an object with ` stdout ` and ` stderr ` properties.
285
+
286
+ ``` js
287
+ const util = require (' util' );
288
+ const execFile = util .promisify (require (' child_process' ).execFile );
289
+ async function getVersion () {
290
+ const {stdout } = await execFile (' node' , [' --version' ]);
291
+ console .log (stdout);
292
+ }
293
+ getVersion ();
294
+ ```
295
+
266
296
### child_process.fork(modulePath[ , args] [ , options ] )
267
297
<!-- YAML
268
298
added: v0.5.0
@@ -1269,4 +1299,5 @@ to `stdout` although there are only 4 characters.
1269
1299
[ `process.on('message')` ] : process.html#process_event_message
1270
1300
[ `process.send()` ] : process.html#process_process_send_message_sendhandle_options_callback
1271
1301
[ `stdio` ] : #child_process_options_stdio
1302
+ [ `util.promisify()` ] : util.html#util_util_promisify_original
1272
1303
[ synchronous counterparts ] : #child_process_synchronous_process_creation
0 commit comments