Follow

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 ~')

· · Web · 0 · 1 · 2
Sign in to participate in the conversation
Aral’s Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!