/// /// import { ChildProcess, ExecSyncOptions, SpawnOptions } from "child_process"; declare type TVerboseLevel = boolean | number | "out" | "err" | "in"; export interface IExecStreamOptions extends SpawnOptions { encoding?: BufferEncoding; } declare type TExecStreamOutputHandler = (stdout?: string, stderr?: string, stdoutBuffer?: string, stderrBuffer?: string, childProcess?: ChildProcess) => any | void; export interface IExecStreamResult { stdout: string; stderr: string; code: number; } /** * Exec a command async and resolve stdout as string. * By default stdout and stderr are hidden. * Set stdLevel to show stdout and / or stderr. * Options argument can be collapsed onto stdlevel argument. * @param command Command to execute. * @param verboseLevel standard outputs to use. 0 is none, 1 is only stdout, 2 is only stderr, 3 is stdout and stdin. * @param options See child_process.exec options. Ignore to call and hide command's stdout. * @returns Promise with stdout if success, stderr if fail */ export declare const execAsync: (command: string, verboseLevel?: TVerboseLevel, options?: ExecSyncOptions) => Promise; /** * Exec a command and return stdout as string. * By default stdout and stderr are hidden. * Set stdLevel to show stdout and / or stderr. * Options argument can be collapsed onto stdlevel argument. * @param command Command to execute. * @param verboseLevel standard outputs to use. 0 is none, 1 is only stdout, 2 is only stderr, 3 is stdout and stdin. * @param options See child_process.execSync options. Ignore to call and hide command's stdout. * @returns Stringified result of command's stdout */ export declare function execSync(command: string, verboseLevel?: TVerboseLevel, options?: ExecSyncOptions): string; /** * Exec and stream all outputs to an handler. * @param command Command to exec as string * @param spawnOptions Options bag to give to Node Spawn * @param outputHandler Executed each time child process output something in stdout or stderr */ export declare function execStream(command: string, spawnOptions: IExecStreamOptions, outputHandler: TExecStreamOutputHandler): Promise; /** * Listen all events when parent process is killed or user tries to kill process. * Process will hang while promises are running. * Useful to clean before closing or interrupt use trying to close process. * Use onProcessWillExit if you want to hook just before process is closing. * Use onProcessError to catch uncaught exception and unhandled rejections. * @param handler Called with event name as first argument * @param eventsToListen All codes to listen on process. */ export declare function onProcessKilled(handler: (eventType: string, ...rest: any[]) => any, eventsToListen?: string[]): void; /** * Listen program errors like unhandled rejections and uncaught exceptions. * @param handler Called with event name as first argument * @param eventsToListen All codes to listen on process. */ export declare function onProcessError(handler: (eventType: string, ...rest: any[]) => any, eventsToListen?: string[]): void; /** * Listen when node will exit. * This will be called even if exit cause is process.exit() usage or if program simply ends. * Please call process.exit after usage to avoid unkillable process, only once. */ export declare function onProcessWillExit(handler: (...rest: any[]) => any): void; export {};