title: node.js, windows 7, spawn chrome, can't set user-data-dir
body: <p>I'm trying to open Google Chrome with node.js on Windows 7 using <code>spawn</code>. It seems to work for all arguments except for setting the <code>user-data-dir</code>. However, <code>--user-data-dir</code> works directly from command line and also works if I call a .cmd file from node, passing the argument through it.</p>
  
  <p>Chrome opens in the background (shows in task manager) but the browser window doesn't open and I have to manually kill the process in task manager to end it.</p>
  
  <p>I get no errors or any indication of what the problem is.</p>
  
  <p>Here is my node code:</p>
  
  <pre><code>var spawn  = require('child_process').spawn;
  var exe = 'C:\\Program Files\\Google\\Chrome\\application\\chrome.exe';
  
  
  //this does not work and gives no errors just starts chrome in the background but fails to open browser window
  // var args = [
  //      '--user-data-dir=C:\\Windows\\Temp\\testingdir',
  //      'http://www.google.com'
  //  ];
  
  //actual output from running this through a .cmd file and echoing out the arguments
  // --user-data-dir=C:\Windows\Temp\testingdir http://www.google.com
  //running the above arguments through a .cmd file from nodejs or manually running them in the cli works
  
  
  
  //this works from nodejs, other arguments work too, just not the --user-data-dir argument
  // var args = ['http://www.google.com'];
  
  chrome = spawn(exe, args);
  
  
  chrome.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
  });
  
  chrome.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
  });
  
  chrome.on('exit', function (code) {
    console.log('child process exited with code ' + code);
    // chrome.kill();
  });
  </code></pre>
  
  <p>As you can see in the commented out code it works as long as I don't try to change the user-data-dir. I've tried different temp directories and setting full access to 'everyone' on the temp directory in case it was a permissions issue.</p>
  
  <p><strong>Update:</strong> I just updated from v0.8.1 I think to the latest v0.8.14 and now when it fails the <code>on('exit', function())</code> actually returns a code.</p>
  
  <pre><code>child process exited with code 20
  </code></pre>
  
  <p>How can I look up this code to find out what it means?</p>
  
  <p><strong>Update 2</strong> The exit code 20 I think was just a one time fluke because I can't reproduce it any more. Trying to test different things is kinda buggy because I have to remember to kill the chrome processes in task manager each time to make sure I get the same results. So it's back to the same results as before, no errors but no chrome window, and some chrome processes running that have to be manually killed.</p>
  
  <p><strong>Update 3</strong>
  I just moved this script over to Ubuntu and changed the exe and args to reflect the different file structure, and it works on Ubuntu.</p>
  
  <pre><code>exe = "/opt/google/chrome/google-chrome"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>args = [
      "http://www.google.com",
      "--user-data-dir=/home/lotus/testdir"
      ];
  </code></pre>
  
  <p>So I can confirm this is specifically related to Chrome on Windows.</p>