title: node.js execute system command synchronously
body: <p>I need in <strong>node.js</strong> function</p>
  
  <pre><code>result = execSync('node -v');
  </code></pre>
  
  <p>that will <strong>synchronously</strong> execute the given command line and return all stdout'ed by that command text.</p>
  
  <blockquote>
    <p>ps. Sync is wrong. I know. Just for personal use.</p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Now we have mgutz's solution which gives us exit code, but not stdout! Still waiting for a more precise answer.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong>mgutz</strong> updated his answer and the solution is here :)<br>
  Also, as <strong>dgo.a</strong> mentioned, there is stand-alone module <a href="https://github.com/jeremyfa/node-exec-sync" rel="noreferrer">exec-sync</a></p>
  
  <p><strong>UPDATE 2014-07-30</strong></p>
  
  <p><a href="https://github.com/arturadib/shelljs" rel="noreferrer">ShellJS</a> lib arrived. Consider this is the best choice for now.</p>
  
  <hr>
  
  <p><strong>UPDATE 2015-02-10</strong></p>
  
  <p><strong>AT LAST!</strong> NodeJS 0.12 supports <code>execSync</code> natively.<br>
  See official <a href="http://nodejs.org/docs/v0.12.0/api/child_process.html#child_process_child_process_execsync_command_options" rel="noreferrer">docs</a></p>