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

322
Vistas
Capturing stdout/stderr of Node-API module running in Electron

I'm developing a Node-API module together with an Electron application. The N-API module is running in the render process of Electron, since it has a pretty complex API, that would be hard to get through a context bridge, and I'm only planning on running local resources anyway. However, none of the printing to stdout done by the N-API module is visible anywhere.

I've tried listening to the process.stdout, which fails because "The _read() method is not implemented":

process.stdout.on("data", (data) => console.log(data));

Piping also doesn't work, because "Cannot pipe, not readable":

const duplexStream = new Stream.Duplex();
duplexStream.on("data", (data) => console.log(data));
process.stdout.pipe(duplexStream);

I even tried overriding the stdout.write() method, which actually worked for calls from within JavaScript, but still didn't show anything from the native module:

process.stdout.write = (data) => {
    console.log(data);
    return true;
};

So is there any way to view the stdout/stderr of a Node-API module from within the script?

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

0

Try enabling ELECTRON_ENABLE_LOGGING environment variable from https://www.electronjs.org/docs/latest/api/environment-variables#electron_enable_logging and check also ELECTRON_LOG_FILE

Electron seems to do something with the stdout in the renderer, I can't find it at the moment but I suppose that it is on purpose.

Try doing this instead of printf in your C++ code:


// Do this only once per instance initialization
// and then destroy it when exiting
auto console_log = Napi::Persistent(env.Global().Get("console").ToObject()
   .Get("log").As<Napi::Function>());

// Do this to print
console_log.Call({Napi::String::New(env, "Displayed through JS")});
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