mirror of https://github.com/winsw/winsw
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.pull/13/head
parent
241e1726ca
commit
39891488bf
1
Main.cs
1
Main.cs
|
@ -373,6 +373,7 @@ namespace winsw
|
||||||
var ps = process.StartInfo;
|
var ps = process.StartInfo;
|
||||||
ps.FileName = executable;
|
ps.FileName = executable;
|
||||||
ps.Arguments = arguments;
|
ps.Arguments = arguments;
|
||||||
|
ps.WorkingDirectory = descriptor.WorkingDirectory;
|
||||||
ps.CreateNoWindow = false;
|
ps.CreateNoWindow = false;
|
||||||
ps.UseShellExecute = false;
|
ps.UseShellExecute = false;
|
||||||
ps.RedirectStandardInput = true; // this creates a pipe for stdin to the new process, instead of having it inherit our stdin.
|
ps.RedirectStandardInput = true; // this creates a pipe for stdin to the new process, instead of having it inherit our stdin.
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -69,11 +70,11 @@ namespace winsw
|
||||||
dom.Load(BasePath + ".xml");
|
dom.Load(BasePath + ".xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
private string SingleElement(string tagName)
|
private string SingleElement(string tagName, bool optional = false)
|
||||||
{
|
{
|
||||||
var n = dom.SelectSingleNode("//" + tagName);
|
var n = dom.SelectSingleNode("//" + tagName);
|
||||||
if (n == null) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
|
if (n == null && !optional) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
|
||||||
return Environment.ExpandEnvironmentVariables(n.InnerText);
|
return n == null ? null : Environment.ExpandEnvironmentVariables(n.InnerText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int SingleIntElement(XmlNode parent, string tagName, int defaultValue)
|
private int SingleIntElement(XmlNode parent, string tagName, int defaultValue)
|
||||||
|
@ -169,6 +170,16 @@ namespace winsw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Combines the contents of all the elements of the given name,
|
/// Combines the contents of all the elements of the given name,
|
||||||
/// or return null if no element exists. Handles whitespace quotation.
|
/// or return null if no element exists. Handles whitespace quotation.
|
||||||
|
|
Loading…
Reference in New Issue