Issue #218 - Also support managing Stdin, which is required in the main executable logic

pull/224/head
Oleg Nenashev 2017-06-08 23:44:24 +02:00
parent 05092376f3
commit 69857d5d8c
2 changed files with 8 additions and 6 deletions

View File

@ -249,7 +249,7 @@ namespace winsw
Log.Info("Starting " + _descriptor.Executable + ' ' + startarguments);
LogHandler executableLogHandler = CreateExecutableLogHandler();
StartProcess(_process, startarguments, _descriptor.Executable, executableLogHandler);
StartProcess(_process, startarguments, _descriptor.Executable, executableLogHandler, true);
ExtensionManager.FireOnProcessStarted(_process);
_process.StandardInput.Close(); // nothing for you to read!
@ -322,7 +322,7 @@ namespace winsw
}
// TODO: Redirect logging to Log4Net once https://github.com/kohsuke/winsw/pull/213 is integrated
StartProcess(stopProcess, stoparguments, executable, null);
StartProcess(stopProcess, stoparguments, executable, null, false);
Log.Debug("WaitForProcessToExit " + _process.Id + "+" + stopProcess.Id);
WaitForProcessToExit(_process);
@ -407,7 +407,7 @@ namespace winsw
Advapi32.SetServiceStatus(handle, ref _wrapperServiceStatus);
}
private void StartProcess(Process processToStart, string arguments, String executable, LogHandler logHandler)
private void StartProcess(Process processToStart, string arguments, String executable, LogHandler logHandler, bool redirectStdin)
{
// Define handler of the completed process
@ -455,7 +455,8 @@ namespace winsw
workingDirectory: _descriptor.WorkingDirectory,
priority: _descriptor.Priority,
callback: processCompletionCallback,
logHandler: logHandler);
logHandler: logHandler,
redirectStdin: redirectStdin);
}
public static int Main(string[] args)

View File

@ -130,8 +130,9 @@ namespace winsw.Util
/// <param name="priority">Priority</param>
/// <param name="callback">Completion callback. If null, the completion won't be monitored</param>
/// <param name="logHandler">Log handler. If enabled, logs will be redirected to the process and then reported</param>
/// <param name="redirectStdin">Redirect standard input</param>
public static void StartProcessAndCallbackForExit(Process processToStart, String executable = null, string arguments = null, Dictionary<string, string> envVars = null,
string workingDirectory = null, ProcessPriorityClass? priority = null, ProcessCompletionCallback callback = null, LogHandler logHandler = null)
string workingDirectory = null, ProcessPriorityClass? priority = null, ProcessCompletionCallback callback = null, bool redirectStdin = true, LogHandler logHandler = null)
{
var ps = processToStart.StartInfo;
ps.FileName = executable ?? ps.FileName;
@ -139,7 +140,7 @@ namespace winsw.Util
ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory;
ps.CreateNoWindow = false;
ps.UseShellExecute = false;
ps.RedirectStandardInput = false;
ps.RedirectStandardInput = redirectStdin;
ps.RedirectStandardOutput = logHandler != null;
ps.RedirectStandardError = logHandler != null;