|
1 | | -/** |
2 | | - * The `node:child_process` module provides the ability to spawn subprocesses in |
3 | | - * a manner that is similar, but not identical, to [`popen(3)`](http://man7.org/linux/man-pages/man3/popen.3.html). This capability |
4 | | - * is primarily provided by the {@link spawn} function: |
5 | | - * |
6 | | - * ```js |
7 | | - * import { spawn } from 'node:child_process'; |
8 | | - * import { once } from 'node:events'; |
9 | | - * const ls = spawn('ls', ['-lh', '/usr']); |
10 | | - * |
11 | | - * ls.stdout.on('data', (data) => { |
12 | | - * console.log(`stdout: ${data}`); |
13 | | - * }); |
14 | | - * |
15 | | - * ls.stderr.on('data', (data) => { |
16 | | - * console.error(`stderr: ${data}`); |
17 | | - * }); |
18 | | - * |
19 | | - * const [code] = await once(ls, 'close'); |
20 | | - * console.log(`child process exited with code ${code}`); |
21 | | - * ``` |
22 | | - * |
23 | | - * By default, pipes for `stdin`, `stdout`, and `stderr` are established between |
24 | | - * the parent Node.js process and the spawned subprocess. These pipes have |
25 | | - * limited (and platform-specific) capacity. If the subprocess writes to |
26 | | - * stdout in excess of that limit without the output being captured, the |
27 | | - * subprocess blocks, waiting for the pipe buffer to accept more data. This is |
28 | | - * identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }` option if the output will not be consumed. |
29 | | - * |
30 | | - * The command lookup is performed using the `options.env.PATH` environment |
31 | | - * variable if `env` is in the `options` object. Otherwise, `process.env.PATH` is |
32 | | - * used. If `options.env` is set without `PATH`, lookup on Unix is performed |
33 | | - * on a default search path search of `/usr/bin:/bin` (see your operating system's |
34 | | - * manual for execvpe/execvp), on Windows the current processes environment |
35 | | - * variable `PATH` is used. |
36 | | - * |
37 | | - * On Windows, environment variables are case-insensitive. Node.js |
38 | | - * lexicographically sorts the `env` keys and uses the first one that |
39 | | - * case-insensitively matches. Only first (in lexicographic order) entry will be |
40 | | - * passed to the subprocess. This might lead to issues on Windows when passing |
41 | | - * objects to the `env` option that have multiple variants of the same key, such as `PATH` and `Path`. |
42 | | - * |
43 | | - * The {@link spawn} method spawns the child process asynchronously, |
44 | | - * without blocking the Node.js event loop. The {@link spawnSync} function provides equivalent functionality in a synchronous manner that blocks |
45 | | - * the event loop until the spawned process either exits or is terminated. |
46 | | - * |
47 | | - * For convenience, the `node:child_process` module provides a handful of |
48 | | - * synchronous and asynchronous alternatives to {@link spawn} and {@link spawnSync}. Each of these alternatives are implemented on |
49 | | - * top of {@link spawn} or {@link spawnSync}. |
50 | | - * |
51 | | - * * {@link exec}: spawns a shell and runs a command within that |
52 | | - * shell, passing the `stdout` and `stderr` to a callback function when |
53 | | - * complete. |
54 | | - * * {@link execFile}: similar to {@link exec} except |
55 | | - * that it spawns the command directly without first spawning a shell by |
56 | | - * default. |
57 | | - * * {@link fork}: spawns a new Node.js process and invokes a |
58 | | - * specified module with an IPC communication channel established that allows |
59 | | - * sending messages between parent and child. |
60 | | - * * {@link execSync}: a synchronous version of {@link exec} that will block the Node.js event loop. |
61 | | - * * {@link execFileSync}: a synchronous version of {@link execFile} that will block the Node.js event loop. |
62 | | - * |
63 | | - * For certain use cases, such as automating shell scripts, the `synchronous counterparts` may be more convenient. In many cases, however, |
64 | | - * the synchronous methods can have significant impact on performance due to |
65 | | - * stalling the event loop while spawned processes complete. |
66 | | - * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/child_process.js) |
67 | | - */ |
68 | 1 | declare module "node:child_process" { |
69 | 2 | import { NonSharedBuffer } from "node:buffer"; |
70 | 3 | import * as dgram from "node:dgram"; |
|
0 commit comments