Created
October 17, 2022 16:05
-
-
Save blakek/a04bec78a7925bd94f4972fa097fef91 to your computer and use it in GitHub Desktop.
Easy Node.js exec
This file contains hidden or 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
function exec(command: string, args?: string[]): Promise<void> { | |
return new Promise((resolve, reject) => { | |
const child = spawn(command, args, { stdio: "inherit" }); | |
child.on("close", (code) => { | |
if (code === 0) { | |
resolve(); | |
} else { | |
reject(new Error(`Command failed with code ${code}`)); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment