Los auxiliares de subprocesos asíncronos y síncronos funcionan en scripts normales.
Un hijo en ejecución mantiene vivo el script hasta su evento close:
import { spawn, execFileSync } from "node:child_process";
const child = spawn("echo", ["hello"]);
child.stdout.on("data", (data) => console.log(String(data).trim())); // hello
child.on("close", (code) => console.log("exit", code)); // exit 0
const output = execFileSync(process.execPath, [
"--snippet",
'process.stdout.write("hi")',
]);
console.log(output.toString()); // hiLas exportaciones disponibles son spawn, spawnSync, exec, execSync, execFile,
execFileSync, fork y ChildProcess. spawnSync devuelve el objeto habitual
con pid, status, signal, stdout, stderr y output.
fork() inicia otro script de Elide con un canal IPC: child.send() y
process.send() intercambian mensajes, que se entregan como eventos message.
La creación de procesos se controla con --allow-run[=CMDS] y
--deny-run <CMDS> cuando las opciones de sandbox están activas.
Reference
Status: Full · Not measured · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
exec(), execSync() | function | Full | Executes a command in a shell |
execFile(), execFileSync() | function | Full | Executes a file without a shell |
spawn(), spawnSync() | function | Full | Spawns a new process using the given command |
fork() | function | Full | Spawns a new Node.js process using the given module path |