@@ -214,6 +214,23 @@ child runs longer than `timeout` milliseconds.
214214* Note: Unlike the exec(3) POSIX system call, ` child_process.exec() ` does not
215215replace the existing process and uses a shell to execute the command.*
216216
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+
217234### child_process.execFile(file[ , args] [ , options ] [ , callback] )
218235<!-- YAML
219236added: v0.1.91
@@ -263,6 +280,19 @@ can be used to specify the character encoding used to decode the stdout and
263280stderr output. If ` encoding ` is ` 'buffer' ` , or an unrecognized character
264281encoding, ` Buffer ` objects will be passed to the callback instead.
265282
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+
266296### child_process.fork(modulePath[ , args] [ , options ] )
267297<!-- YAML
268298added: v0.5.0
@@ -1269,4 +1299,5 @@ to `stdout` although there are only 4 characters.
12691299[ `process.on('message')` ] : process.html#process_event_message
12701300[ `process.send()` ] : process.html#process_process_send_message_sendhandle_options_callback
12711301[ `stdio` ] : #child_process_options_stdio
1302+ [ `util.promisify()` ] : util.html#util_util_promisify_original
12721303[ synchronous counterparts ] : #child_process_synchronous_process_creation
0 commit comments