From 3735a1a54225a058914f4356c2d271bb12fab6a7 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 7 Jun 2024 22:51:32 +0530 Subject: fix(ext/node): support stdin child_process IPC & fd stdout/stderr (#24106) Add supports for "ipc" and fd options in child_process spawn API. Internal changes: Adds a hidden rid and "ipc_for_internal_use" option to Deno.Command. Used by `node:child_process` Example: ```js const out = fs.openSync("./logfile.txt", 'a') const proc = spawn(process.execPath, ["./main.mjs", "child"], { stdio: ["ipc", out, "inherit"] }); ``` Ref #16753 --- tests/specs/node/stdio_ipc/__test__.jsonc | 5 +++++ tests/specs/node/stdio_ipc/main.mjs | 16 ++++++++++++++++ tests/specs/node/stdio_ipc/main.out | 1 + 3 files changed, 22 insertions(+) create mode 100644 tests/specs/node/stdio_ipc/__test__.jsonc create mode 100644 tests/specs/node/stdio_ipc/main.mjs create mode 100644 tests/specs/node/stdio_ipc/main.out (limited to 'tests/specs/node/stdio_ipc') diff --git a/tests/specs/node/stdio_ipc/__test__.jsonc b/tests/specs/node/stdio_ipc/__test__.jsonc new file mode 100644 index 000000000..8ec9880fd --- /dev/null +++ b/tests/specs/node/stdio_ipc/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run -A main.mjs", + "output": "main.out", + "exitCode": 0 +} diff --git a/tests/specs/node/stdio_ipc/main.mjs b/tests/specs/node/stdio_ipc/main.mjs new file mode 100644 index 000000000..4a1a8ddbd --- /dev/null +++ b/tests/specs/node/stdio_ipc/main.mjs @@ -0,0 +1,16 @@ +import { spawn } from "node:child_process"; +import process from "node:process"; + +if (process.argv[2] === "child") { + process.send("hahah"); +} else { + const proc = spawn(process.execPath, ["./main.mjs", "child"], { + stdio: ["ipc", "inherit", "inherit"], + }); + + proc.on("message", function (msg) { + console.log(`msg: ${msg}`); + proc.kill(); + Deno.exit(0); + }); +} diff --git a/tests/specs/node/stdio_ipc/main.out b/tests/specs/node/stdio_ipc/main.out new file mode 100644 index 000000000..7979ca2eb --- /dev/null +++ b/tests/specs/node/stdio_ipc/main.out @@ -0,0 +1 @@ +msg: hahah -- cgit v1.2.3