mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Allow passing env to child process
This commit is contained in:
1 parent
548d59d07e
commit
769a35024f
3 files changed
+18
-4
No files matched your search
@@ -9,6 +9,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user