sindresorhus / execa

Process execution for humans
MIT License
6.87k stars 219 forks source link

stdout/stderr with 'inherit' + transform should not capture output #1125

Closed bcoughlan closed 5 months ago

bcoughlan commented 5 months ago

121 implemented the ability to transform stdout/stderr while using inherit. However the output is captured, like pipe mode, which is a source of memory leaks for long running processes.

Example:

import { execa } from 'execa';

async function main() {
    await execa({
        stdout: [function* (line) {
            yield `[test] ${line}`;
        }, 'inherit'],
        stderr: [function* (line) {
            yield `[test] ${line}`;
        }, 'inherit'],
    })('sh', ['ls', '-la', '/bad'])
}

main()

Expected: thrown error does not contain stdio or stderr properties.

Actual: output includes...

  stderr: '[test] /bin/ls: /bin/ls: cannot execute binary file',
  stdio: [
    undefined,
    '',
    '[test] /bin/ls: /bin/ls: cannot execute binary file'
  ],
ehmicky commented 5 months ago

Hi @bcoughlan,

Thanks for reaching out.

To avoid capturing output, the buffer option must be set to false.

bcoughlan commented 5 months ago

Thank you so much, that worked. Apologies for the noise.

wtto00 commented 2 weeks ago

Hello, sorry to bother you.

Can I retain the original output text color in the terminal when both inherit and transform are present?

Or could this become a feature?

I want to match the output text content for corresponding processing without affecting the original output format.


Sorry, I got the answer in https://github.com/sindresorhus/execa/issues/69#issuecomment-704901634 . Apologies for the noise.