From fe5ca3ff27d3d94386edab0f9328df534da599aa Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 16 Apr 2017 21:29:26 +0200 Subject: [PATCH] child_process: support promisified `exec(File)` Author: Benjamin Gruenbaum Author: Anna Henningsen PR-URL: https://github.com/nodejs/node/pull/12442 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Myles Borins Reviewed-By: Evan Lucas Reviewed-By: William Kapke Reviewed-By: Timothy Gu Reviewed-By: Teddy Katz --- doc/api/child_process.md | 31 +++++++++++++++++ lib/child_process.js | 10 +++++- .../test-child-process-promisified.js | 34 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-child-process-promisified.js diff --git a/doc/api/child_process.md b/doc/api/child_process.md index b3e3001417cc4e..39ac6c62a603fa 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -214,6 +214,23 @@ child runs longer than `timeout` milliseconds. *Note: Unlike the exec(3) POSIX system call, `child_process.exec()` does not replace the existing process and uses a shell to execute the command.* +If this method is invoked as its [`util.promisify()`][]ed version, it returns +a Promise for an object with `stdout` and `stderr` properties. + +For example: + +```js +const util = require('util'); +const exec = util.promisify(require('child_process').exec); + +async function lsExample() { + const {stdout, stderr} = await exec('ls'); + console.log('stdout:', stdout); + console.log('stderr:', stderr); +} +lsExample(); +``` + ### child_process.execFile(file[, args][, options][, callback])