diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index 0ca2a958ec..b6137e0d17 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -866,7 +866,7 @@ export function spawnSync( windowsVerbatimArguments = false, } = options; const [ - _stdin_ = "pipe", // TODO(bartlomieju): use this? + stdin_ = "pipe", stdout_ = "pipe", stderr_ = "pipe", _channel, // TODO(kt3k): handle this correctly @@ -881,6 +881,7 @@ export function spawnSync( env: mapValues(env, (value) => value.toString()), stdout: toDenoStdio(stdout_), stderr: toDenoStdio(stderr_), + stdin: stdin_ == "inherit" ? "inherit" : "null", uid, gid, windowsRawArguments: windowsVerbatimArguments, diff --git a/tests/unit_node/child_process_test.ts b/tests/unit_node/child_process_test.ts index 6a1d1dbc54..23de928db5 100644 --- a/tests/unit_node/child_process_test.ts +++ b/tests/unit_node/child_process_test.ts @@ -823,3 +823,35 @@ Deno.test(function spawnCommandNullStdioArray() { assertEquals(ret.status, 0); }); + +Deno.test( + function stdinInherit() { + const script = ` + function timeoutPromise(promise, timeout) { + return new Promise((resolve, reject) => { + const timeoutId = setTimeout(() => { + Deno.exit(69); + }, timeout); + promise.then((value) => { + clearTimeout(timeoutId); + resolve(value); + }, (reason) => { + clearTimeout(timeoutId); + reject(reason); + }); + }); + } + + await timeoutPromise(Deno.stdin.read(new Uint8Array(1)), 100) + `; + + const output = spawnSync(Deno.execPath(), ["eval", script], { + stdio: "inherit", + }); + + // We want to timeout to occur because the stdin isn't 'null' + assertEquals(output.status, 69); + assertEquals(output.stdout, null); + assertEquals(output.stderr, null); + }, +);