Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
Spying on stdout of stdio: inherit spawn process

Have a simple function I'm trying to unit test:

const {spawn} = require('child_process');

function exec (command, args) {
  return spawn(command, args, {
    stdio: `inherit`
  });
}

Since this is using inherit, echo.stdout.on will not work, though I would presume that with the stdio being shared with the parent process, and the parent process presumably being the running script, that I could just override process.stdout.write (or console.log), but this did not work (neither did overwriting global.process.stdout.write). How can I spy on write using the above exec with the following not working?


let str = '';
const {write} = process.stdout;
process.stdout.write = (s) => {
  str += s; // Does not run
};
const echo = exec('echo', ['hello', 'world']);
echo.on('exit', () => {
  process.stdout.write = write;
  throw (new Error('Result ' + str));
});
setTimeout(() => {
  echo.kill();
}, 1000);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda