Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Pipe spawned process stdout to function on flush

My goal is to spawn another binary file in a child process, then handle the stdout on a line-by-line basis (And do some processing against that line). For testing I'm using Node. To do this I tried a readable & writable stream but it a type error is throwed saying "The argument 'stdio' is invalid. Received Writable"

const rs = new stream.Readable();
const ws = new stream.Writable();

const child = cp.spawn("node", [], {
    stdio: [process.stdin, ws, process.stderr]
})

let count = 0;
ws.on("data", (data) => {
    console.log(data, count)
});

Anyone have any ideas?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

One way is to use the stdio streams returned by spawn and manually pipe them:

const child = cp.spawn("node", [])

child.stdin.pipe(process.stdin)
child.stdout.pipe(ws)
child.stderr.pipe(process.stderr)

let count = 0;
ws.on("data", (data) => {
    console.log(data, count)
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!