I'm getting a cryptic error when I try to pass the stdout from on process to the stdin of another process.
// test.js
const child_process = require("child_process");
const proc = child_process.spawn("ls", ["-a"]);
const res = child_process.spawnSync("head", ["-n", "3"], {
stdio: [proc.stdout, "pipe", "pipe"],
});
console.log(res.toString("utf8"));
When I run node test.js
with node version v16.13.1
, instead of seeing the result of ls -a | head -n 3
, I get the following error:
node test.js[12920]: c:\ws\src\spawn_sync.cc:932: Assertion `0 && "invalid child stdio type"' failed.
1: 00007FF63F1230AF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112511
2: 00007FF63F0B2216 DSA_meth_get_flags+65542
3: 00007FF63F0B25D1 DSA_meth_get_flags+66497
4: 00007FF63EFD2C69 v8::internal::wasm::WasmCode::code_comments_offset+35065
...
34: 00007FF63FF63A88 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+14472
35: 00007FFE6C787034 BaseThreadInitThunk+20
36: 00007FFE6E642651 RtlUserThreadStart+33
Am I not allowed to mix child_process.spawn
and child_process.spawn_sync
?
This works if I change child_process.spawn_sync
to child_process.spawn
, but I need the command call to be synchronous.