Created
May 31, 2024 09:31
-
-
Save laruiss/6f281ef35a89e4d83ff5616a9f96ae13 to your computer and use it in GitHub Desktop.
Run shell command programmatically from node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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