sindresorhus / hook-std

Hook and modify stdout and stderr
MIT License
54 stars 12 forks source link

Cover output of spawned processes that inherit stdio #9

Open medikoo opened 8 years ago

medikoo commented 8 years ago

It might be nice to somehow support that, at least via option.

Without that, output that hook-std captures doesn't necessary cover all output as seen from initialized process in a console.

I think it's possible only via overriding ChildProcess.prototype.spawn and act accordingly after recognizing the intention.

sindresorhus commented 8 years ago

I would like this too, but I don't think it's possible. From what I can remember, the stdio inheriting logic is done in native code in libuv, not in ChildProcess.prototype.spawn. But happy to be proven wrong in the form of a pull request 😀.

medikoo commented 8 years ago

@sindresorhus I investigated it and indeed it looks there's no way. Still I would leave it open, maybe other adventurers will find some miraculous solution.

sindresorhus commented 8 years ago

Sure

orta commented 3 years ago

As a passer-by who hit this issue, I don't know if future folks have the same kind of problems as me (I wanted guarantees that I was getting pretty much the exact stdout/stderr with ASNI, but not spamming the console.)

What I did instead was use node-pty to spawn an in-memory pseudo-terminal which I could extract pretty much the exact same stdout/stderr.

sindresorhus commented 3 years ago

@orta Yup. That works, but node-pty is a native Node.js addon, which comes with all kinds of problems. It's not something I would depend on in a reusable package. If only Node.js had PTY built-in...