From 2908f323e1cabd44329c8fcf67fd4b1fde41030b Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 1 Aug 2011 17:40:46 -0700 Subject: [PATCH] win: fix test-child-process-exec-cwd --- lib/child_process_uv.js | 7 ++++++- test/simple/test-child-process-exec-cwd.js | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/child_process_uv.js b/lib/child_process_uv.js index af276f9..6eed97d 100644 --- a/lib/child_process_uv.js +++ b/lib/child_process_uv.js @@ -49,7 +49,12 @@ function createSocket(pipe, readable) { exports.exec = function(command /*, options, callback */) { var rest = Array.prototype.slice.call(arguments, 1); - var args = ['/bin/sh', ['-c', command]].concat(rest); + var args; + if (process.platform == 'win32') { + args = ['cmd.exe', ['/c', command]].concat(rest); + } else { + args = ['/bin/sh', ['-c', command]].concat(rest); + } return exports.execFile.apply(this, args); }; diff --git a/test/simple/test-child-process-exec-cwd.js b/test/simple/test-child-process-exec-cwd.js index 80c42bc..fb9f138 100644 --- a/test/simple/test-child-process-exec-cwd.js +++ b/test/simple/test-child-process-exec-cwd.js @@ -26,7 +26,17 @@ var exec = require('child_process').exec; var success_count = 0; var error_count = 0; -var child = exec('pwd', {cwd: '/dev'}, function(err, stdout, stderr) { +var pwdcommand, dir; + +if (process.platform == 'win32') { + pwdcommand = 'echo %cd%'; + dir = 'c:\\windows'; +} else { + pwdcommand = 'pwd'; + dir = '/etc'; +} + +var child = exec(pwdcommand, {cwd: dir}, function(err, stdout, stderr) { if (err) { error_count++; console.log('error!: ' + err.code); @@ -35,7 +45,8 @@ var child = exec('pwd', {cwd: '/dev'}, function(err, stdout, stderr) { assert.equal(false, err.killed); } else { success_count++; - assert.equal(true, /^\/dev\b/.test(stdout)); + console.log(stdout); + assert.ok(stdout.indexOf(dir) == 0); } }); -- 2.7.4