UNPKG

extra-child-process

Version:

Useful additions to inbuilt child_process module.

257 lines (254 loc) 12.4 kB
import { ExecException, ExecSyncOptions, PromiseWithChild, ChildProcess, ExecFileSyncOptions, SpawnSyncOptions, SpawnSyncReturns } from 'child_process'; export { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, CommonExecOptions, CommonOptions, CommonSpawnOptions, ExecException, ExecFileException, ExecFileOptions, ExecFileOptionsWithBufferEncoding, ExecFileOptionsWithOtherEncoding, ExecFileOptionsWithStringEncoding, ExecFileSyncOptions, ExecFileSyncOptionsWithBufferEncoding, ExecFileSyncOptionsWithStringEncoding, ExecOptions, ExecOptionsWithBufferEncoding, ExecOptionsWithStringEncoding, ForkOptions, IOType, MessageOptions, MessagingOptions, ProcessEnvOptions, PromiseWithChild, SendHandle, Serializable, SerializationType, SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, SpawnSyncOptions, SpawnSyncOptionsWithBufferEncoding, SpawnSyncOptionsWithStringEncoding, SpawnSyncReturns, StdioNull, StdioOptions, StdioPipe, StdioPipeNamed, execFileSync, execSync, fork, spawn, spawnSync } from 'child_process'; /** * Return value from exec*Async(). * [📘](https://github.com/nodef/extra-child-process/wiki/ExecAsyncReturns) */ interface ExecAsyncReturns { /** Standard output written by child process. */ stdout: string | Buffer; /** Standard error written by child process. */ stderr: string | Buffer; } /** * Error from exec*Async(). * [📘](https://github.com/nodef/extra-child-process/wiki/ExecAsyncException) */ interface ExecAsyncException extends ExecException, ExecAsyncReturns { } /** * Callback for exec*(). * [📘](https://github.com/nodef/extra-child-process/wiki/ExecCallback) * @param error exec error * @param stdout standard output after exec * @param stderr standard error after exec */ type ExecCallback = (error: ExecException, stdout: string | Buffer, stderr: string | Buffer) => void; /** * Execute a command within a shell, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execAsync) * @param command command to run, with space-separated arguments * @param options options \{cwd, env, ...\} * @returns output \{stdout, stderr\} */ declare function execAsync(command: string, options?: ExecSyncOptions): PromiseWithChild<ExecAsyncReturns>; /** * Execute a command within a shell, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/exec) * @param command command to run, with space-separated arguments * @param callback callback function (err, stdout, stderr) * @returns child process */ declare function exec(command: string, callback: ExecCallback): ChildProcess; /** * Execute a command within a shell, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/exec) * @param command command to run, with space-separated arguments * @param options options \{cwd, env, ...\} * @param callback callback function (err, stdout, stderr) * @returns child process */ declare function exec(command: string, options: ExecSyncOptions, callback: ExecCallback): ChildProcess; /** * Execute a command within a shell, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/exec) * @param command command to run, with space-separated arguments * @param options options \{cwd, env, ...\} * @returns output \{stdout, stderr\} */ declare function exec(command: string, options?: ExecSyncOptions): PromiseWithChild<ExecAsyncReturns>; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFileAsync) * @param file name or path of executable file * @param options options \{cwd, env, ...\} * @returns output \{stdout, stderr\} */ declare function execFileAsync(file: string, options?: ExecFileSyncOptions): PromiseWithChild<ExecAsyncReturns>; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFileAsync) * @param file name or path of executable file * @param args list of arguments * @param options options \{cwd, env, ...\} * @returns output \{stdout, stderr\} */ declare function execFileAsync(file: string, args: string[], options?: ExecFileSyncOptions): PromiseWithChild<ExecAsyncReturns>; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFile) * @param file name or path of executable file * @param callback callback function (err, stdout, stderr) * @returns child process */ declare function execFile(file: string, callback: ExecCallback): ChildProcess; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFile) * @param file name or path of executable file * @param options options \{cwd, env, ...\} * @param callback callback function (err, stdout, stderr) * @returns child process */ declare function execFile(file: string, options: ExecFileSyncOptions, callback: ExecCallback): ChildProcess; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFile) * @param file name or path of executable file * @param args list of arguments * @param callback callback function (err, stdout, stderr) * @returns child process */ declare function execFile(file: string, args: string[], callback: ExecCallback): ChildProcess; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFile) * @param file name or path of executable file * @param args list of arguments * @param options options \{cwd, env, ...\} * @param callback callback function (err, stdout, stderr) * @returns child process */ declare function execFile(file: string, args: string[], options: ExecFileSyncOptions, callback: ExecCallback): ChildProcess; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFile) * @param file name or path of executable file * @param options options \{cwd, env, ...\} * @returns output \{stdout, stderr\} */ declare function execFile(file: string, options?: ExecFileSyncOptions): PromiseWithChild<ExecAsyncReturns>; /** * Execute an executable without a shell by default, buffering any output. * [📘](https://github.com/nodef/extra-child-process/wiki/execFile) * @param file name or path of executable file * @param args list of arguments * @param options options \{cwd, env, ...\} * @returns output \{stdout, stderr\} */ declare function execFile(file: string, args: string[], options?: ExecFileSyncOptions): PromiseWithChild<ExecAsyncReturns>; /** * Spawn new process using given command and arguments. * [📘](https://github.com/nodef/extra-child-process/wiki/spawnAsync) * @param command command to run * @param options options \{cwd, env, ...\} * @returns output \{pid, output, stdout, stderr, status, signal\} */ declare function spawnAsync(command: string, options?: SpawnSyncOptions): PromiseWithChild<SpawnSyncReturns<string | Buffer>>; /** * Spawn new process using given command and arguments. * [📘](https://github.com/nodef/extra-child-process/wiki/spawnAsync) * @param command command to run * @param args list of arguments * @param options options \{cwd, env, ...\} * @returns output \{pid, output, stdout, stderr, status, signal\} */ declare function spawnAsync(command: string, args: string[], options?: SpawnSyncOptions): PromiseWithChild<SpawnSyncReturns<string | Buffer>>; interface WhichOptions { /** Current working directory (win32 only). */ cwd?: string; /** Paths to search for. */ paths?: string[]; /** Extension names to match (win32 only). */ extnames?: string[]; } /** * Check whether a file satisfies a test. * [📘](https://github.com/nodef/extra-child-process/wiki/FileTestFunction) * @param file name of file * @returns whether test is satisfied */ type FileTestFunction = (file: string) => boolean; /** * Callback for which*(). * [📘](https://github.com/nodef/extra-child-process/wiki/WhichCallback) * @param error which error * @param path executable path */ type WhichCallback = (error: NodeJS.ErrnoException, path?: string) => void; /** * Callback for whichAll*(). * [📘](https://github.com/nodef/extra-child-process/wiki/WhichAllCallback) * @param error which error * @param paths executable paths */ type WhichAllCallback = (error: NodeJS.ErrnoException, paths?: string[]) => void; /** * Locate path of executable for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichSync) * @param cmd command to locate * @param options which options \{cwd, paths\} * @returns path of executable */ declare function whichSync(cmd: string | RegExp | FileTestFunction, options?: WhichOptions): string; /** * Locate paths of all matching executables for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichAllSync) * @param cmd command to locate * @param options which options \{cwd, paths\} * @returns paths of executables */ declare function whichAllSync(cmd: string | RegExp | FileTestFunction, options?: WhichOptions): string[]; /** * Locate path of executable for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichAsync) * @param cmd command to locate * @param options which options \{cwd, paths\} * @returns path of executable */ declare function whichAsync(cmd: string | RegExp | FileTestFunction, options?: WhichOptions): Promise<string>; /** * Locate paths of all matching executables for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichAllAsync) * @param cmd command to locate * @param options which options \{cwd, paths\} * @returns paths of executables */ declare function whichAllAsync(cmd: string | RegExp | FileTestFunction, options?: WhichOptions): Promise<string[]>; /** * Locate path of executable for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/which) * @param cmd command to locate * @param callback callback function (err, path) */ declare function which(cmd: string | RegExp | FileTestFunction, callback: WhichCallback): void; /** * Locate path of executable for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/which) * @param cmd command to locate * @param options which options \{cwd, paths\} * @param callback callback function (err, path) */ declare function which(cmd: string | RegExp | FileTestFunction, options: WhichOptions, callback: WhichCallback): void; /** * Locate path of executable for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/which) * @param cmd command to locate * @param options which options \{cwd, paths\} * @returns path of executable */ declare function which(cmd: string | RegExp | FileTestFunction, options?: WhichOptions): Promise<string>; /** * Locate paths of all matching executables for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichAll) * @param cmd command to locate * @param callback callback function (err, path) */ declare function whichAll(cmd: string | RegExp | FileTestFunction, callback: WhichAllCallback): void; /** * Locate paths of all matching executables for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichAll) * @param cmd command to locate * @param options which options \{cwd, paths\} * @param callback callback function (err, path) */ declare function whichAll(cmd: string | RegExp | FileTestFunction, options: WhichOptions, callback: WhichAllCallback): void; /** * Locate paths of all matching executables for given command. * [📘](https://github.com/nodef/extra-child-process/wiki/whichAll) * @param cmd command to locate * @param options which options \{cwd, paths\} * @returns paths of executables */ declare function whichAll(cmd: string | RegExp | FileTestFunction, options?: WhichOptions): Promise<string[]>; export { ExecAsyncException, ExecAsyncReturns, ExecCallback, FileTestFunction, WhichAllCallback, WhichCallback, WhichOptions, exec, execAsync, execFile, execFileAsync, spawnAsync, which, whichAll, whichAllAsync, whichAllSync, whichAsync, whichSync };