Skip to content

Instantly share code, notes, and snippets.

@blakek
Created October 17, 2022 16:05
Show Gist options
  • Save blakek/a04bec78a7925bd94f4972fa097fef91 to your computer and use it in GitHub Desktop.
Save blakek/a04bec78a7925bd94f4972fa097fef91 to your computer and use it in GitHub Desktop.
Easy Node.js exec
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