Node.js synchronous shell exec
<p>I am having a problem with async shell executes in node.js.</p>

<p>In my case, node.js is installed on a Linux operating system on a raspberry pi. I want to fill an array with values that are parsed from a shell script which is called on the pi. This works fine, however, the exec() function is called asynchronously. </p>

<p>I need the function to be absolute synchron to avoid messing up my whole system. Is there any way to achieve this? Currently I am trying a lib called .exe, but the code still seems to behave asynchron.</p>

<p>Here's my code:</p>

<pre><code>function execute(cmd, cb)
{
  child = exec(cmd, function(error, stdout, stderr)
  {
    cb(stdout, stderr);
  });
}



function chooseGroup()
{
  var groups = [];

  execute("bash /home/pi/scripts/group_show.sh", function(stdout, stderr)
  {
    groups_str  = stdout;
    groups      = groups_str.split("\n");
  });

  return groups;
}


//Test
console.log(chooseGroup());
</code></pre>