diff --git a/src/node_child_process.cc b/src/node_child_process.cc index 4dc3d437af..6902455dd0 100644 --- a/src/node_child_process.cc +++ b/src/node_child_process.cc @@ -9,6 +9,8 @@ #include #include +extern char **environ; + namespace node { using namespace v8; @@ -276,7 +278,7 @@ static inline int SetNonBlocking(int fd) { // Note that args[0] must be the same as the "file" param. This is an // execvp() requirement. -int ChildProcess::Spawn(const char *file, char *const args[], char *const env[]) { +int ChildProcess::Spawn(const char *file, char *const args[], char **env) { assert(pid_ == 0); assert(stdout_fd_ == -1); assert(stderr_fd_ == -1); @@ -315,11 +317,11 @@ int ChildProcess::Spawn(const char *file, char *const args[], char *const env[]) close(stdin_pipe[1]); // close write end dup2(stdin_pipe[0], STDIN_FILENO); + environ = env; + execvp(file, args); perror("execvp()"); _exit(127); - - // TODO search PATH and use: execve(file, argv, env); } // Parent. diff --git a/src/node_child_process.h b/src/node_child_process.h index 1cdd974d09..b37db9f36a 100644 --- a/src/node_child_process.h +++ b/src/node_child_process.h @@ -28,7 +28,7 @@ class ChildProcess : EventEmitter { ChildProcess(); ~ChildProcess(); - int Spawn(const char *file, char *const argv[], char *const env[]); + int Spawn(const char *file, char *const argv[], char **env); int Write(const char *str, size_t len); int Close(void); int Kill(int sig); diff --git a/test/simple/test-child-process-env.js b/test/simple/test-child-process-env.js new file mode 100644 index 0000000000..4b5d902030 --- /dev/null +++ b/test/simple/test-child-process-env.js @@ -0,0 +1,12 @@ +process.mixin(require("../common")); +child = process.createChildProcess('/usr/bin/env', [], {'HELLO' : 'WORLD'}); +response = ""; + +child.addListener("output", function (chunk) { + puts("stdout: " + JSON.stringify(chunk)); + if (chunk) response += chunk; +}); + +process.addListener('exit', function () { + assert.ok(response.indexOf('HELLO=WORLD') >= 0); +});