February 24, 2007 [Issue 1004] New: Changed environment not passed to child process | ||||
---|---|---|---|---|
| ||||
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... -- |
February 24, 2007 [Issue 1004] Changed environment not passed to child process | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1004 ------- Comment #1 from t_demmer@web.de 2007-02-24 11:11 ------- 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_ ); } -- |
Copyright © 1999-2021 by the D Language Foundation