From 88107b7cd413f1dded39727513681473a5ab2419 Mon Sep 17 00:00:00 2001 From: jjasper4 Date: Sat, 8 Nov 2008 20:27:46 +0000 Subject: [PATCH] Add envars from config.xml to the Environment.SetEnvironmentVariable to enable the usage of those envars in arguments, etc. Note: OnStart must first call descriptor.EnvironmentVariables for this to work. The envars are written to the EventLog information. git-svn-id: https://svn.kenai.com/svn/winsw~subversion/trunk@8 c8b2a3fe-9b5b-6a51-a37e-dc31b0e308fa --- Main.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Main.cs b/Main.cs index 74af685..c628f13 100644 --- a/Main.cs +++ b/Main.cs @@ -133,7 +133,11 @@ namespace winsw Dictionary map = new Dictionary(); foreach (XmlNode n in dom.SelectNodes("//env")) { - map[n.Attributes["name"].Value] = Environment.ExpandEnvironmentVariables(n.Attributes["value"].Value); + string key = n.Attributes["name"].Value; + string value = Environment.ExpandEnvironmentVariables(n.Attributes["value"].Value); + map[key] = value; + + Environment.SetEnvironmentVariable(key, value); } return map; } @@ -223,6 +227,12 @@ namespace winsw protected override void OnStart(string[] args) { + var envs = descriptor.EnvironmentVariables; + foreach (string key in envs.Keys) + { + EventLog.WriteEntry("envar " + key + '=' + envs[key]); + } + HandleFileCopies(); EventLog.WriteEntry("Starting "+descriptor.Executable+' '+descriptor.Arguments); @@ -237,7 +247,6 @@ namespace winsw ps.RedirectStandardOutput = true; ps.RedirectStandardError = true; - var envs = descriptor.EnvironmentVariables; foreach (string key in envs.Keys) ps.EnvironmentVariables[key] = envs[key];