digitalmars.D.bugs - [Issue 1004] New: Changed environment not passed to child process
- d-bugmail puremagic.com (33/33) Feb 24 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1004
- d-bugmail puremagic.com (32/32) Feb 24 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1004
http://d.puremagic.com/issues/show_bug.cgi?id=1004
Summary: Changed environment not passed to child process
Product: D
Version: 1.007
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla digitalmars.com
ReportedBy: t_demmer web.de
/*
Bug in spawnvp (and maybe others):
Only the initial environment is copied to the child process,
modifications get lost
Compile and run, type "SET",
you should see a line
YYY=xxxx
but you don't.
Works fine with gdc -mno-cygwin,
so I guess it is a phobos bug.
*/
import std.process;
extern(Windows) void SetEnvironmentVariableA(char *lpName, char *lpValue);
int
main(char[][] args){
SetEnvironmentVariableA(toStringz("YYY"),toStringz("xxxx"));
return spawnvp(0,"cmd.exe",args);
}
I did not find guidelines for setting values for Priority,
"Assign To", and "Cc", so sorry for bothering everyone...
--
Feb 24 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1004
These two versions work for me, someone with a way better knowledge
of D may optimize the clumsy version of spawnvp
int spawnvpe(int mode, char[] pathname, char[][]argv, char[][] envi){
char** argv_ = cast(char**)alloca((char*).sizeof * (1 + argv.length));
char** envi_ = cast(char**)alloca((char*).sizeof * (1 + envi.length));
toAStringz(argv, argv_);
toAStringz(envi, envi_);
return std.c.process.spawnvpe(mode, toStringz(pathname), argv_, envi_ );
}
int
spawnvp(int mode, char[] pathname, char[][] argv){
char** argv_ = cast(char**)alloca((char*).sizeof * (1 + argv.length));
toAStringz(argv, argv_);
char[][] env;
char *eBase=cast(char *)GetEnvironmentStringsA();
for(char *str=eBase; *str; ++str){
int slen = std.string.strlen(str);
env.length = env.length+1;
env[env.length-1].length = slen;
size_t i = 0;
while(*str){
env[env.length-1][i++]= *str++;
}
}
char** env_ = cast(char**)alloca((char*).sizeof * (1 + env.length));
toAStringz(env, env_);
FreeEnvironmentStringsA(cast(char **)eBase);
return std.c.process.spawnvpe(mode, toStringz(pathname), argv_, env_ );
}
--
Feb 24 2007








d-bugmail puremagic.com