title: Store nodejs exec stdout in var
body: <p>I would like make this function return the result of the exec command in a var.  How would I go about doing this?</p>
  
  <pre class="lang-javascript prettyprint-override"><code>// System Serial Number
  function systemSerialNumber(response) {
    console.log("Request handler 'systemSerialNumber' was called.");
    exec("dmidecode -t 1 | grep 'Serial Number:' | cut -d: -f2 | sed -e 's/^[ \t]*//g'", function (error, stdout, stderr) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.write(stdout);
      response.end();
    });
  }
  </code></pre>