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

744
Vistas
Node.js : How to make spawn function synchronous instead of using spawnSync?

I'm currently using spawnSync and stdio:inherit to get the logs printed on my console. However I'm looking for custom logging to a separate file, in case if anything fails during the spawn.

I'm looking to create a wrapper around

spawn

so that it has following properties :

  • Synchronous function where output is stored in a variable
  • View output on the console
  • Write stdout and stderr to a file

For instance :

const result = spawnSync('ls', [ '-l', '-a' ], { stdio: 'inherit'}); // will print as it's processing
console.log(result.stdout); // will print null

const result = spawnSync('ls', [ '-l', '-a' ], { encoding: 'utf-8' }); // won't print anything
console.log(result.stdout); // will print ls results only on completion

I need result such that it will print while it's processing and write to a file at the same time

Also I'm looking for some strategy or solution from node.js side apart from shell scripting

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I guess we can't make all three possible because of the limitation of node.js

As per the documentationenter image description here

If we are trying to use stdio:'inherit' , we can either redirect output to parent stdout stream or file using

fs.openSync()

Because of the limitation, we can't use custom streams too.

over 4 years ago · Santiago Trujillo 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