Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!