import child from "child_process" ; import sudo from "sudo-prompt" ; interface ExecResponse { stdout ? : string | Buffer ; stderr ? : string | Buffer ; } class ExecError extends Error { constructor ( public error , public stdout ? , public stderr ? ) { super ( error . message ) ; } } export async function run ( command , sudoPrompt = true ) { return new Promise < ExecResponse > ( ( resolve , reject ) => { if ( sudoPrompt ) { sudo . exec ( command , { name : "wiregui" } , function ( error ? , stdout ? , stderr ? ) { if ( ! error ) { resolve ( { stdout , stderr } ) ; } else { reject ( new ExecError ( error , stdout , stderr ) ) ; } } ) ; } else { child . exec ( command , function ( error , stdout , stderr ) { if ( ! error ) { resolve ( { stdout , stderr } ) ; } else { reject ( new ExecError ( error , stdout , stderr ) ) ; } } ) ; } } ) ; }