Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 02, 2013 std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Good day, I'm trying to write a script in D for building D projects. I want to set the environment variable LIB for optlink to be able to pick up library files from where I put them after compiling dependencies. The problem is, that the std.process.setenv is only available under Linux and std.process.system("set LIB=target") does not do anything. I guess std.process.system creates a separate process every time, sets the local environment variable and exists, erasing the local environment variable. I tried supplying multiple commands at once by specifying a multi-line argument to std.process.system, but it didn't work at all. How can I set my local envoronment variables so that further calls to std.process.system can pick it up? Regards, Gor Gyolchanyan. |
February 02, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gor Gyolchanyan |
On 02.02.2013 12:41, Gor Gyolchanyan wrote:
> Good day,
>
> I'm trying to write a script in D for building D projects. I want to set
> the environment variable LIB for optlink to be able to pick up library
> files from where I put them after compiling dependencies.
>
> The problem is, that the std.process.setenv is only available under
> Linux and std.process.system("set LIB=target") does not do anything. I
> guess std.process.system creates a separate process every time, sets the
> local environment variable and exists, erasing the local environment
> variable.
> I tried supplying multiple commands at once by specifying a multi-line
> argument to std.process.system, but it didn't work at all.
>
> How can I set my local envoronment variables so that further calls to
> std.process.system can pick it up?
Have you tried putenv? It is only declared in core.sys.posix.stdlib, but the dmc-runtime-library must have it as dmd is also using it.
|
February 03, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gor Gyolchanyan | On 02/02/2013 03:41 AM, Gor Gyolchanyan wrote: > How can I set my local envoronment variables so that further calls to > std.process.system can pick it up? std.process has the nice AA-like 'environment': import std.process; void main() { environment["MY_ENV_VAR"] = "42"; system("echo $MY_ENV_VAR"); // <-- prints "42" assert(shell("echo $MY_ENV_VAR") == "42\n"); } There is also 'setenv' in that module but I find 'environment' more convenient. (Also, 'setenv' is evil because it has a bool parameter. ;)) Ali |
February 03, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | pathSeparator ~ path ~ pathToMyDir Ali Çehreli wrote:
> import std.process;
>
> void main()
> {
> environment["MY_ENV_VAR"] = "42";
>
> system("echo $MY_ENV_VAR"); // <-- prints "42"
> assert(shell("echo $MY_ENV_VAR") == "42\n");
> }
>
> There is also 'setenv' in that module but I find 'environment' more convenient. (Also, 'setenv' is evil because it has a bool parameter. ;))
Win7, dmd 2.061: environment seems to be read only.
string path = environment["PATH"];
// OK
environment("PATH"] = pathSeparator ~ path ~ pathToMyDir ;
// failed, unidentified identifier
setenv("PATH", pathSeparator ~ path ~ pathToMyDir, true);
// failed, undefined identifier
Do you know a way to set it via system/shell calls, notably under windows?
Peter
|
February 06, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Sommerfeld | On Sunday, 3 February 2013 at 19:05:01 UTC, Peter Sommerfeld wrote: > Do you know a way to set it via system/shell calls, notably under windows? > > Peter You might want to use Tango: module env; // 2013-01-08 // dmd2.061 + Siegelord Tango-D2-d2port import tango.sys.Environment; import tango.io.Stdout; void main(string[] args) { string VAR = "TESTENVVAR"; string VAL1 = "VAL1"; string VAL2 = "VAL2"; assert(Environment.get(VAR) is null); Environment.set(VAR, VAL1); assert(Environment.get(VAR) == VAL1); Environment.set(VAR, ""); assert(Environment.get(VAR) is null); Environment.set(VAR, VAL2); assert(Environment.get(VAR) == VAL2); Environment.set(VAR, null); assert(Environment.get(VAR) is null); Environment.set(VAR, VAL1); foreach (key, value; Environment.get) Stdout.formatln("'{}' = '{}'", key, value); foreach(i, arg; args) { auto p = Environment.exePath (cast (char[]) arg); Stdout.formatln("exePath(arg[{}] '{}') = '{}'", i, arg, p); } } |
February 06, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to HeiHon | HeiHon <heiko.honrath@web.de> schrieb: > On Sunday, 3 February 2013 at 19:05:01 UTC, Peter Sommerfeld wrote: >> Do you know a way to set it via system/shell calls, notably under windows? >> >> Peter > You might want to use Tango: > > module env; > // 2013-01-08 > // dmd2.061 + Siegelord Tango-D2-d2port > import tango.sys.Environment; Hmmm, AFAIK it is outdated, isn't it ? I also hesitate to introduce major dependencies for this small point. Can you point me to the sources of this Tango version please. May be I can reuse a small part of it. Thanks, Peter |
February 06, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Sommerfeld | > Hmmm, AFAIK it is outdated, isn't it ? I also hesitate to introduce > major dependencies for this small point. It was originally for D1, but SiegeLord ported almost all of it to D2. > Can you point me to the sources of this Tango version please. > May be I can reuse a small part of it. https://github.com/SiegeLord/Tango-D2 There are still some very useful things in Tango that you don't find in Phobos (e.g. logging) and it plays nicely together with Phobos. |
February 06, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to HeiHon | Am 06.02.2013, 14:51 Uhr, schrieb HeiHon <heiko.honrath@web.de>:
> https://github.com/SiegeLord/Tango-D2
>
> There are still some very useful things in Tango that you don't find in Phobos (e.g. logging) and it plays nicely together with Phobos.
Thanks, interesting read. Will have a deeper look in it later.
Peter
|
February 07, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Sommerfeld | Hi Peter. This works for me on Win7 with DMD2.061 http://dpaste.dzfl.pl/64529e76 in this example here you are mixing (] parentheses :O Don't think this is your real code, is it :O | | V V > environment("PATH"] = pathSeparator ~ path ~ pathToMyDir ; > // failed, unidentified identifier |
February 07, 2013 Re: std.process.system and friends | ||||
---|---|---|---|---|
| ||||
Posted in reply to notna | notna wrote: > This works for me on Win7 with DMD2.061 > > http://dpaste.dzfl.pl/64529e76 Yes that works, but that was not quite the question. The point is you cannot *set* the path variable. But meanwhile I think it isn't a good idea anyway. The PATH belongs to the user/system, not to programs. Otherwise that may introduce some harm... >> environment("PATH"] = pathSeparator ~ path ~ pathToMyDir ; >> // failed, unidentified identifier Yep, typo! Peter |
Copyright © 1999-2021 by the D Language Foundation