1 | declare module "child_process" {
|
2 | import * as events from "events";
|
3 | import * as net from "net";
|
4 | import { Writable, Readable, Stream, Pipe } from "stream";
|
5 |
|
6 | interface ChildProcess extends events.EventEmitter {
|
7 | stdin: Writable | null;
|
8 | stdout: Readable | null;
|
9 | stderr: Readable | null;
|
10 | readonly channel?: Pipe | null;
|
11 | readonly stdio: [
|
12 | Writable | null,
|
13 | Readable | null,
|
14 | Readable | null,
|
15 | Readable | Writable | null | undefined,
|
16 | Readable | Writable | null | undefined
|
17 | ];
|
18 | readonly killed: boolean;
|
19 | readonly pid: number;
|
20 | readonly connected: boolean;
|
21 | kill(signal?: string): void;
|
22 | send(message: any, callback?: (error: Error | null) => void): boolean;
|
23 | send(message: any, sendHandle?: net.Socket | net.Server, callback?: (error: Error | null) => void): boolean;
|
24 | send(message: any, sendHandle?: net.Socket | net.Server, options?: MessageOptions, callback?: (error: Error | null) => void): boolean;
|
25 | disconnect(): void;
|
26 | unref(): void;
|
27 | ref(): void;
|
28 |
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | addListener(event: string, listener: (...args: any[]) => void): this;
|
39 | addListener(event: "close", listener: (code: number, signal: string) => void): this;
|
40 | addListener(event: "disconnect", listener: () => void): this;
|
41 | addListener(event: "error", listener: (err: Error) => void): this;
|
42 | addListener(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
|
43 | addListener(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
|
44 |
|
45 | emit(event: string | symbol, ...args: any[]): boolean;
|
46 | emit(event: "close", code: number, signal: string): boolean;
|
47 | emit(event: "disconnect"): boolean;
|
48 | emit(event: "error", err: Error): boolean;
|
49 | emit(event: "exit", code: number | null, signal: string | null): boolean;
|
50 | emit(event: "message", message: any, sendHandle: net.Socket | net.Server): boolean;
|
51 |
|
52 | on(event: string, listener: (...args: any[]) => void): this;
|
53 | on(event: "close", listener: (code: number, signal: string) => void): this;
|
54 | on(event: "disconnect", listener: () => void): this;
|
55 | on(event: "error", listener: (err: Error) => void): this;
|
56 | on(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
|
57 | on(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
|
58 |
|
59 | once(event: string, listener: (...args: any[]) => void): this;
|
60 | once(event: "close", listener: (code: number, signal: string) => void): this;
|
61 | once(event: "disconnect", listener: () => void): this;
|
62 | once(event: "error", listener: (err: Error) => void): this;
|
63 | once(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
|
64 | once(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
|
65 |
|
66 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
67 | prependListener(event: "close", listener: (code: number, signal: string) => void): this;
|
68 | prependListener(event: "disconnect", listener: () => void): this;
|
69 | prependListener(event: "error", listener: (err: Error) => void): this;
|
70 | prependListener(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
|
71 | prependListener(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
|
72 |
|
73 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
74 | prependOnceListener(event: "close", listener: (code: number, signal: string) => void): this;
|
75 | prependOnceListener(event: "disconnect", listener: () => void): this;
|
76 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
77 | prependOnceListener(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
|
78 | prependOnceListener(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
|
79 | }
|
80 |
|
81 |
|
82 | interface ChildProcessWithoutNullStreams extends ChildProcess {
|
83 | stdin: Writable;
|
84 | stdout: Readable;
|
85 | stderr: Readable;
|
86 | readonly stdio: [
|
87 | Writable,
|
88 | Readable,
|
89 | Readable,
|
90 | Readable | Writable | null | undefined,
|
91 | Readable | Writable | null | undefined
|
92 | ];
|
93 | }
|
94 |
|
95 | interface MessageOptions {
|
96 | keepOpen?: boolean;
|
97 | }
|
98 |
|
99 | type StdioOptions = "pipe" | "ignore" | "inherit" | Array<("pipe" | "ipc" | "ignore" | "inherit" | Stream | number | null | undefined)>;
|
100 |
|
101 | interface ProcessEnvOptions {
|
102 | uid?: number;
|
103 | gid?: number;
|
104 | cwd?: string;
|
105 | env?: NodeJS.ProcessEnv;
|
106 | }
|
107 |
|
108 | interface CommonOptions extends ProcessEnvOptions {
|
109 | |
110 |
|
111 |
|
112 | windowsHide?: boolean;
|
113 | |
114 |
|
115 |
|
116 | timeout?: number;
|
117 | }
|
118 |
|
119 | interface SpawnOptions extends CommonOptions {
|
120 | argv0?: string;
|
121 | stdio?: StdioOptions;
|
122 | detached?: boolean;
|
123 | shell?: boolean | string;
|
124 | windowsVerbatimArguments?: boolean;
|
125 | }
|
126 |
|
127 | interface SpawnOptionsWithoutStdio extends SpawnOptions {
|
128 | stdio?: 'pipe' | Array<null | undefined | 'pipe'>;
|
129 | }
|
130 |
|
131 | function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
132 | function spawn(command: string, options: SpawnOptions): ChildProcess;
|
133 | function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
134 | function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptions): ChildProcess;
|
135 |
|
136 | interface ExecOptions extends CommonOptions {
|
137 | shell?: string;
|
138 | maxBuffer?: number;
|
139 | killSignal?: string;
|
140 | }
|
141 |
|
142 | interface ExecOptionsWithStringEncoding extends ExecOptions {
|
143 | encoding: BufferEncoding;
|
144 | }
|
145 |
|
146 | interface ExecOptionsWithBufferEncoding extends ExecOptions {
|
147 | encoding: string | null;
|
148 | }
|
149 |
|
150 | interface ExecException extends Error {
|
151 | cmd?: string;
|
152 | killed?: boolean;
|
153 | code?: number;
|
154 | signal?: string;
|
155 | }
|
156 |
|
157 |
|
158 | function exec(command: string, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
159 |
|
160 |
|
161 | function exec(command: string, options: { encoding: "buffer" | null } & ExecOptions, callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
|
162 |
|
163 |
|
164 | function exec(command: string, options: { encoding: BufferEncoding } & ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
165 |
|
166 |
|
167 |
|
168 | function exec(command: string, options: { encoding: string } & ExecOptions, callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
|
169 |
|
170 |
|
171 | function exec(command: string, options: ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
172 |
|
173 |
|
174 | function exec(
|
175 | command: string,
|
176 | options: ({ encoding?: string | null } & ExecOptions) | undefined | null,
|
177 | callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
178 | ): ChildProcess;
|
179 |
|
180 |
|
181 | namespace exec {
|
182 | function __promisify__(command: string): Promise<{ stdout: string, stderr: string }>;
|
183 | function __promisify__(command: string, options: { encoding: "buffer" | null } & ExecOptions): Promise<{ stdout: Buffer, stderr: Buffer }>;
|
184 | function __promisify__(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<{ stdout: string, stderr: string }>;
|
185 | function __promisify__(command: string, options: ExecOptions): Promise<{ stdout: string, stderr: string }>;
|
186 | function __promisify__(command: string, options?: ({ encoding?: string | null } & ExecOptions) | null): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
187 | }
|
188 |
|
189 | interface ExecFileOptions extends CommonOptions {
|
190 | maxBuffer?: number;
|
191 | killSignal?: string;
|
192 | windowsVerbatimArguments?: boolean;
|
193 | }
|
194 | interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
|
195 | encoding: BufferEncoding;
|
196 | }
|
197 | interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
|
198 | encoding: 'buffer' | null;
|
199 | }
|
200 | interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
|
201 | encoding: string;
|
202 | }
|
203 |
|
204 | function execFile(file: string): ChildProcess;
|
205 | function execFile(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
|
206 | function execFile(file: string, args?: ReadonlyArray<string> | null): ChildProcess;
|
207 | function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
|
208 |
|
209 |
|
210 | function execFile(file: string, callback: (error: Error | null, stdout: string, stderr: string) => void): ChildProcess;
|
211 | function execFile(file: string, args: ReadonlyArray<string> | undefined | null, callback: (error: Error | null, stdout: string, stderr: string) => void): ChildProcess;
|
212 |
|
213 |
|
214 | function execFile(file: string, options: ExecFileOptionsWithBufferEncoding, callback: (error: Error | null, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
|
215 | function execFile(
|
216 | file: string,
|
217 | args: ReadonlyArray<string> | undefined | null,
|
218 | options: ExecFileOptionsWithBufferEncoding,
|
219 | callback: (error: Error | null, stdout: Buffer, stderr: Buffer) => void,
|
220 | ): ChildProcess;
|
221 |
|
222 |
|
223 | function execFile(file: string, options: ExecFileOptionsWithStringEncoding, callback: (error: Error | null, stdout: string, stderr: string) => void): ChildProcess;
|
224 | function execFile(
|
225 | file: string,
|
226 | args: ReadonlyArray<string> | undefined | null,
|
227 | options: ExecFileOptionsWithStringEncoding,
|
228 | callback: (error: Error | null, stdout: string, stderr: string) => void,
|
229 | ): ChildProcess;
|
230 |
|
231 |
|
232 |
|
233 | function execFile(
|
234 | file: string,
|
235 | options: ExecFileOptionsWithOtherEncoding,
|
236 | callback: (error: Error | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
237 | ): ChildProcess;
|
238 | function execFile(
|
239 | file: string,
|
240 | args: ReadonlyArray<string> | undefined | null,
|
241 | options: ExecFileOptionsWithOtherEncoding,
|
242 | callback: (error: Error | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
243 | ): ChildProcess;
|
244 |
|
245 |
|
246 | function execFile(file: string, options: ExecFileOptions, callback: (error: Error | null, stdout: string, stderr: string) => void): ChildProcess;
|
247 | function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: ExecFileOptions, callback: (error: Error | null, stdout: string, stderr: string) => void): ChildProcess;
|
248 |
|
249 |
|
250 | function execFile(
|
251 | file: string,
|
252 | options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
|
253 | callback: ((error: Error | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
|
254 | ): ChildProcess;
|
255 | function execFile(
|
256 | file: string,
|
257 | args: ReadonlyArray<string> | undefined | null,
|
258 | options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
|
259 | callback: ((error: Error | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
|
260 | ): ChildProcess;
|
261 |
|
262 |
|
263 | namespace execFile {
|
264 | function __promisify__(file: string): Promise<{ stdout: string, stderr: string }>;
|
265 | function __promisify__(file: string, args: string[] | undefined | null): Promise<{ stdout: string, stderr: string }>;
|
266 | function __promisify__(file: string, options: ExecFileOptionsWithBufferEncoding): Promise<{ stdout: Buffer, stderr: Buffer }>;
|
267 | function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding): Promise<{ stdout: Buffer, stderr: Buffer }>;
|
268 | function __promisify__(file: string, options: ExecFileOptionsWithStringEncoding): Promise<{ stdout: string, stderr: string }>;
|
269 | function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithStringEncoding): Promise<{ stdout: string, stderr: string }>;
|
270 | function __promisify__(file: string, options: ExecFileOptionsWithOtherEncoding): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
271 | function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithOtherEncoding): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
272 | function __promisify__(file: string, options: ExecFileOptions): Promise<{ stdout: string, stderr: string }>;
|
273 | function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptions): Promise<{ stdout: string, stderr: string }>;
|
274 | function __promisify__(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
275 | function __promisify__(
|
276 | file: string,
|
277 | args: string[] | undefined | null,
|
278 | options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
|
279 | ): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
280 | }
|
281 |
|
282 | interface ForkOptions extends ProcessEnvOptions {
|
283 | execPath?: string;
|
284 | execArgv?: string[];
|
285 | silent?: boolean;
|
286 | stdio?: StdioOptions;
|
287 | detached?: boolean;
|
288 | windowsVerbatimArguments?: boolean;
|
289 | }
|
290 | function fork(modulePath: string, args?: ReadonlyArray<string>, options?: ForkOptions): ChildProcess;
|
291 |
|
292 | interface SpawnSyncOptions extends CommonOptions {
|
293 | argv0?: string;
|
294 | input?: string | Buffer | NodeJS.TypedArray | DataView;
|
295 | stdio?: StdioOptions;
|
296 | killSignal?: string | number;
|
297 | maxBuffer?: number;
|
298 | encoding?: string;
|
299 | shell?: boolean | string;
|
300 | windowsVerbatimArguments?: boolean;
|
301 | }
|
302 | interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
|
303 | encoding: BufferEncoding;
|
304 | }
|
305 | interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
|
306 | encoding: string;
|
307 | }
|
308 | interface SpawnSyncReturns<T> {
|
309 | pid: number;
|
310 | output: string[];
|
311 | stdout: T;
|
312 | stderr: T;
|
313 | status: number;
|
314 | signal: string;
|
315 | error?: Error;
|
316 | }
|
317 | function spawnSync(command: string): SpawnSyncReturns<Buffer>;
|
318 | function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
319 | function spawnSync(command: string, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
320 | function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<Buffer>;
|
321 | function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
322 | function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
323 | function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptions): SpawnSyncReturns<Buffer>;
|
324 |
|
325 | interface ExecSyncOptions extends CommonOptions {
|
326 | input?: string | Buffer | Uint8Array;
|
327 | stdio?: StdioOptions;
|
328 | shell?: string;
|
329 | killSignal?: string | number;
|
330 | maxBuffer?: number;
|
331 | encoding?: string;
|
332 | }
|
333 | interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
|
334 | encoding: BufferEncoding;
|
335 | }
|
336 | interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
|
337 | encoding: string;
|
338 | }
|
339 | function execSync(command: string): Buffer;
|
340 | function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string;
|
341 | function execSync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Buffer;
|
342 | function execSync(command: string, options?: ExecSyncOptions): Buffer;
|
343 |
|
344 | interface ExecFileSyncOptions extends CommonOptions {
|
345 | input?: string | Buffer | NodeJS.TypedArray | DataView;
|
346 | stdio?: StdioOptions;
|
347 | killSignal?: string | number;
|
348 | maxBuffer?: number;
|
349 | encoding?: string;
|
350 | shell?: boolean | string;
|
351 | }
|
352 | interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
|
353 | encoding: BufferEncoding;
|
354 | }
|
355 | interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
|
356 | encoding: string;
|
357 | }
|
358 | function execFileSync(command: string): Buffer;
|
359 | function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string;
|
360 | function execFileSync(command: string, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
361 | function execFileSync(command: string, options?: ExecFileSyncOptions): Buffer;
|
362 | function execFileSync(command: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptionsWithStringEncoding): string;
|
363 | function execFileSync(command: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
364 | function execFileSync(command: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptions): Buffer;
|
365 | }
|