Problem: you want to use Node’s promisified child_process.exec (Node 12+) but you also want to stream in progress from executed command. Solution:
import childProcess from 'child_process'
import { promisify } from 'util'
const _exec = promisify(childProcess.exec)
async function exec(command) {
const commandPromise = _exec(command)
const commandProcess = commandPromise.child
commandProcess.stdout.pipe(process.stdout)
await commandPromise
}
// e.g.
await exec('ls -laR ~')