Skip to content

Instantly share code, notes, and snippets.

@117
Created February 13, 2019 16:25
Show Gist options
  • Save 117/85fb0b4af99ee2c9a21750ada087e269 to your computer and use it in GitHub Desktop.
Save 117/85fb0b4af99ee2c9a21750ada087e269 to your computer and use it in GitHub Desktop.
Exec command example node js
import { exec, ExecException } from "child_process";
export interface CommandResult {
error: ExecException;
stdout: string;
stderr: string;
}
export class Command {
constructor(public command: string = "") {}
add(command: string) {
this.command = this.command
? this.command.concat(` && ${command}`)
: command;
return this;
}
execute(): Promise<CommandResult> {
return new Promise(resolve => {
exec(this.command, (err, sout, serr) =>
resolve({ error: err, stdout: sout, stderr: serr })
);
});
}
toString() {
return this.command;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment