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

289
Vistas
execSync - How to see ongoing script execution

I am using execSync to execute a shell script within a javascript script

const { execSync } = require('child_process');
const shell = (cmd) => execSync(cmd, { encoding: 'utf8' });
shell('node jest');

When I run jest from my terminal, I see each step in the console as the script is ongoing.

When I run shell(script), I only see the whole results at the end of the script.

Question

What should I do to output in live the execution of a script using execSync?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After some research I found the proper method.

child_process.exec() is "synchronously asynchronous", meaning although the .exec is asynchronous, it waits for the child process to end and tries to return all the buffered data at once

child_process.spawn() returns an object with stdout and stderr stream

Hence I opted to use spawn and created

const shellAsync = (cmd) => {
  const script = spawn(cmd);

  script.stdout.on('data', (data) => {
    console.log(`${data}`);
  });

  script.stderr.on('data', (data) => {
    console.error(`${data}`);
  });

  script.on('close', (code) => {
    console.log(`child process exited with code ${code}`);
  });
};
about 4 years ago · Juan Pablo Isaza Denunciar
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