import * as childProcess from "child_process" ; import { ChildProcess , ExecException } from "child_process" ; export async function startProcess ( commandLine , verbose = false ) { return new Promise < void > ( ( resolve , reject ) => { if ( verbose ) { console . log ( `Starting: ${ commandLine }` ) ; } childProcess . exec ( commandLine , ( error , stdout , stderr ) => { if ( error ) { reject ( error ) ; } else { resolve ( ) ; } } ) ; } ) ; } export function startDetachedProcess ( commandLine , verbose = false ) { if ( verbose ) { console . log ( `Starting: ${ commandLine }` ) ; } const subprocess = childProcess . spawn ( commandLine , [ ] , { detached : true , shell : true , stdio : "ignore" , windowsHide : false , } ) ; subprocess . on ( "error" , ( err ) => { console . log ( `Unable to run command: ${ commandLine }.\n${ err }` ) ; } ) ; subprocess . unref ( ) ; return subprocess ; } export function stopProcess ( processId ) { if ( processId ) { try { if ( process . platform === "win32" ) { childProcess . spawn ( "taskkill" , [ "/pid" , `${ processId }` , "/f" , "/t" ] ) ; } else { process . kill ( processId ) ; } } catch ( err ) { console . log ( `Unable to kill process id ${ processId }: ${ err }` ) ; } } }