Browse Source

Allow passing env to child process

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
769a35024f
  1. 8
      src/node_child_process.cc
  2. 2
      src/node_child_process.h
  3. 12
      test/simple/test-child-process-env.js

8
src/node_child_process.cc

@ -9,6 +9,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
extern char **environ;
namespace node { namespace node {
using namespace v8; 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 // Note that args[0] must be the same as the "file" param. This is an
// execvp() requirement. // 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(pid_ == 0);
assert(stdout_fd_ == -1); assert(stdout_fd_ == -1);
assert(stderr_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 close(stdin_pipe[1]); // close write end
dup2(stdin_pipe[0], STDIN_FILENO); dup2(stdin_pipe[0], STDIN_FILENO);
environ = env;
execvp(file, args); execvp(file, args);
perror("execvp()"); perror("execvp()");
_exit(127); _exit(127);
// TODO search PATH and use: execve(file, argv, env);
} }
// Parent. // Parent.

2
src/node_child_process.h

@ -28,7 +28,7 @@ class ChildProcess : EventEmitter {
ChildProcess(); ChildProcess();
~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 Write(const char *str, size_t len);
int Close(void); int Close(void);
int Kill(int sig); int Kill(int sig);

12
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);
});
Loading…
Cancel
Save