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

170
Visualizações
Directly return ${stdout} instead of logging on console

I have an app creator and, using the Username NPM package, I can get the OS' username with this:

Browser.ExecJS("username.sync()")

Tested on Electron.

So, this is the format my app creator uses to read from JS:

Browser.ExecJS("")

In this example, it's calling username.sync(). And it works.

But when running this:

Browser.ExecJS("const{exec}=require(`child_process`);exec(`jq -r '.next_var' /tmp/eventsheet.json`,(error,stdout,stderr)=>{if(error){console.log(`error:${error.message}`);return}if(stderr){console.log(`stderr:${stderr}`);return}console.log(`${stdout}`);return});")

It gets "0". And then correctly logs the stdout on console. But, it should get the same as it logs on console, instead of "0".

Its inspired by this code about how to run a native shell program directly from Electron/NodeJS: https://stackabuse.com/executing-shell-commands-with-node-js/

So, I think it should replace the console.log by some sort of return. How do I re-factor it? Thanks in advance.

UPDATE: based on this suggested answer (that doesn't works), this is the closest template to put it to work using return instead of console.log as output:

const { promisify } = require('util');
const exec = promisify(require('child_process').exec)

module.exports.getGitUser = async function getGitUser () {
  const name = await exec('git config --global user.name')
  const email = await exec('git config --global user.email')
  return { name, email }
};

But still doesn't works. What I need is this:

const{exec}=require(`child_process`);exec(`jq -r '.next_var' /tmp/eventsheet.json`,(error,stdout,stderr)=>{if(error){console.log(`error:${error.message}`);return}if(stderr){console.log(`stderr:${stderr}`);return}console.log(`${stdout}`);return});

But using return instead of console.log.

about 4 years ago · Juan Pablo Isaza
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