Permalink
Browse files

change the wrapped process working directory

set the working directory of the wrapped process with the location of the winsw executable, or the path defined in the configuration file.
  • Loading branch information...
1 parent 241e172 commit 39891488bf04565a03298fa4be96e0c3087dfe02 @mereth mereth committed Mar 17, 2013
Showing with 15 additions and 3 deletions.
  1. +1 −0 Main.cs
  2. +14 −3 ServiceDescriptor.cs
View
@@ -373,6 +373,7 @@ private void StartProcess(Process process, string arguments, String executable)
var ps = process.StartInfo;
ps.FileName = executable;
ps.Arguments = arguments;
+ ps.WorkingDirectory = descriptor.WorkingDirectory;
ps.CreateNoWindow = false;
ps.UseShellExecute = false;
ps.RedirectStandardInput = true; // this creates a pipe for stdin to the new process, instead of having it inherit our stdin.
View
@@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
+using System.Reflection;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Text;
@@ -69,11 +70,11 @@ public ServiceDescriptor()
dom.Load(BasePath + ".xml");
}
- private string SingleElement(string tagName)
+ private string SingleElement(string tagName, bool optional = false)
{
var n = dom.SelectSingleNode("//" + tagName);
- if (n == null) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
- return Environment.ExpandEnvironmentVariables(n.InnerText);
+ if (n == null && !optional) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
+ return n == null ? null : Environment.ExpandEnvironmentVariables(n.InnerText);
}
private int SingleIntElement(XmlNode parent, string tagName, int defaultValue)
@@ -169,6 +170,16 @@ public string Stoparguments
}
}
+ /// <summary>
+ /// Optional working directory.
+ /// </summary>
+ public string WorkingDirectory {
+ get {
+ var wd = SingleElement("workingdirectory", true);
+ return String.IsNullOrEmpty(wd) ? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) : wd;
+ }
+ }
+
/// <summary>
/// Combines the contents of all the elements of the given name,
/// or return null if no element exists. Handles whitespace quotation.

0 comments on commit 3989148

Please sign in to comment.