title: Using nodejs's spawn causes "unknown option -- " and "[Error: spawn ENOENT]" errors
body: <p>I'm trying to get <code>spawn</code> to effect an <code>rm -rf node_modules</code> followed by <code>npm install</code> (on windows 7; <em>n</em>x commands courtesy of a transparently installed CygWin. All <em>n</em>x commands resolve on a commandline just fine).</p>
  
  <p>I initially had this using <code>exec</code>, but wanted to catch the stdout/stderr information as it occurred, so I figured I'd use <code>spawn</code>, and rewrote the code to use that. However, that breaks everything.</p>
  
  <p>The <code>rm</code> command, rewritten, became this:</p>
  
  <pre><code>var spawn = require("child_process").spawn,
      child = spawn("rm", ["-rf", "node_modules"]);
  child.stdout.on('data', function (data) { console.log(data.toString()); });
  child.stderr.on('data', function (data) { console.log(data.toString()); });
  child.on('error', function() { console.log(arguments); });
  </code></pre>
  
  <p>However, running this generates the following error:</p>
  
  <pre><code>rm: unknown option -- ,
  
  Try `rm --help' for more information.
  </code></pre>
  
  <p>The <code>npm</code> command, rewritten, became this:</p>
  
  <pre><code>var spawn = require("child_process").spawn,
      child = spawn("npm", ["install"]);
  child.stdout.on('data', function (data) { console.log(data.toString()); });
  child.stderr.on('data', function (data) { console.log(data.toString()); });
  child.on('error', function() { console.log(arguments); });
  </code></pre>
  
  <p>However, running this generates the following error:</p>
  
  <pre><code>{
    '0': {
      [Error: spawn ENOENT]
      code: 'ENOENT',
      errno: 'ENOENT',
      syscall: 'spawn'
    }
  }
  </code></pre>
  
  <p>How do I make spawn run the same commands that worked fine using <code>exec</code> without it throwing up errors all over the place? And why does this not work? Reading the API, <a href="http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options" rel="noreferrer">http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options</a>, seems to suggest this is precisely how one is supposed to use spawn...</p>