This repository has been archived by the owner. It is now read-only.

64-bit child_process.exec()'s cwd option does not work on Windows x64 #4083

morkai opened this Issue Oct 5, 2012 · 4 comments


None yet
3 participants

morkai commented Oct 5, 2012

require('child_process').exec('cd', {cwd: 'C:/Windows/Fonts'}, function(err, stdout) {

The above snippet when executed in node 0.8.11 32-bit on Windows 7 x64 results in C:\Windows\Fonts, but when executed in node 0.8.11 64-bit it results in C:\.

spawn works (pwd is a Gow utility):

require('child_process').spawn('pwd', [], {cwd: 'C:/Windows/Fonts'}).stdout.on('data', function(data) {
  console.log('%s', data);

Related to einaros/ws#115

morkai commented Oct 5, 2012

It looks like %windir%\System32\cmd.exe (which is used by default on a 64-bit system) is the problem.
Passing %windir%\SysWOW64\cmd.exe instead of cmd.exe in child_process.exec() on a 64-bit system may be the solution (I can't test it with node, because I don't know how to compile a 64-bit version of node).

Instead of this:

    file = 'cmd.exe';


    file = 'cmd.exe';
    if (process.arch === 'x64') {
      var windir = process.env.windir || process.env.WINDIR;
      if (typeof windir === 'string' && windir.length > 0) {
        file = windir + '\\SysWOW64\\cmd.exe';

Prefixing the command passed by the user with 'cd /D ' + options.cwd + ' & ' should work too.

cjihrig commented Dec 1, 2014

Is this still an issue? I can't reproduce. c08da46 (among many other changes) also landed some time ago, which should help with selecting the proper version of cmd.exe.


jasnell commented May 18, 2015

@orangemocha ... thoughts on this one?

morkai commented May 18, 2015

This is no longer an issue. Both 32-bit and 64-bit versions of v0.12.3 return the same, valid result: C:\Windows\Fonts.

@jasnell jasnell closed this May 18, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.