Skip to content

Instantly share code, notes, and snippets.

@laruiss
Created May 31, 2024 09:31
Show Gist options
  • Save laruiss/6f281ef35a89e4d83ff5616a9f96ae13 to your computer and use it in GitHub Desktop.
Save laruiss/6f281ef35a89e4d83ff5616a9f96ae13 to your computer and use it in GitHub Desktop.
Run shell command programmatically from node
import { exec } from 'node:child_process'
async function run (cmd) {
const child = exec(cmd, (err) => {
if (err) console.error(err)
})
child.stderr.pipe(process.stderr)
child.stdout.pipe(process.stdout)
await new Promise((resolve) => child.on('close', resolve))
}
export default run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment