0

So, can anybody point out why this is logging out undefined to the console?

var runner = require('child_process');

function getString(cmd) {
  runner.exec(cmd, function (err, stdout) {
    if (stdout) {
      // console.log(stdout);
      return stdout;
    }
  });
}

console.log(getString('git config user.name'));

Ideally, I'm just wanting to store a string return from a function inside a variable. I'm just trying to get my head around variable scoping here and make a simple command line script - though I've dumbed it down to get the question answered.

0 Answers0