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
remotes/git-svn
jjasper4 2008-11-08 20:27:46 +00:00
parent d51e11a7a4
commit 88107b7cd4
1 changed files with 11 additions and 2 deletions

13
Main.cs
View File

@ -133,7 +133,11 @@ namespace winsw
Dictionary<string, string> map = new Dictionary<string, string>();
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];