Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda