Leave STDIN open

pull/614/head
NextTurn 2020-07-28 00:00:00 +08:00 committed by Next Turn
parent db91805e45
commit 4d187eb882
2 changed files with 3 additions and 12 deletions

View File

@ -130,7 +130,6 @@ namespace WinSW.Util
/// <param name="workingDirectory">Working directory</param> /// <param name="workingDirectory">Working directory</param>
/// <param name="priority">Priority</param> /// <param name="priority">Priority</param>
/// <param name="onExited">Completion callback. If null, the completion won't be monitored</param> /// <param name="onExited">Completion callback. If null, the completion won't be monitored</param>
/// <param name="redirectStdin">Redirect standard input</param>
/// <param name="logHandler">Log handler. If enabled, logs will be redirected to the process and then reported</param> /// <param name="logHandler">Log handler. If enabled, logs will be redirected to the process and then reported</param>
public static void StartProcessAndCallbackForExit( public static void StartProcessAndCallbackForExit(
Process processToStart, Process processToStart,
@ -140,7 +139,6 @@ namespace WinSW.Util
string? workingDirectory = null, string? workingDirectory = null,
ProcessPriorityClass? priority = null, ProcessPriorityClass? priority = null,
Action<Process>? onExited = null, Action<Process>? onExited = null,
bool redirectStdin = true,
LogHandler? logHandler = null, LogHandler? logHandler = null,
bool hideWindow = false) bool hideWindow = false)
{ {
@ -150,7 +148,6 @@ namespace WinSW.Util
ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory; ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory;
ps.CreateNoWindow = hideWindow; ps.CreateNoWindow = hideWindow;
ps.UseShellExecute = false; ps.UseShellExecute = false;
ps.RedirectStandardInput = redirectStdin;
ps.RedirectStandardOutput = logHandler != null; ps.RedirectStandardOutput = logHandler != null;
ps.RedirectStandardError = logHandler != null; ps.RedirectStandardError = logHandler != null;

View File

@ -5,7 +5,6 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using log4net; using log4net;
using WinSW.Extensions; using WinSW.Extensions;
@ -282,11 +281,9 @@ namespace WinSW
this.ExtensionManager.FireOnWrapperStarted(); this.ExtensionManager.FireOnWrapperStarted();
LogHandler executableLogHandler = this.CreateExecutableLogHandler(); LogHandler executableLogHandler = this.CreateExecutableLogHandler();
this.StartProcess(this.process, startArguments, this.descriptor.Executable, executableLogHandler, true); this.StartProcess(this.process, startArguments, this.descriptor.Executable, executableLogHandler);
this.ExtensionManager.FireOnProcessStarted(this.process); this.ExtensionManager.FireOnProcessStarted(this.process);
this.process.StandardInput.Close(); // nothing for you to read!
try try
{ {
string? poststartExecutable = this.descriptor.PoststartExecutable; string? poststartExecutable = this.descriptor.PoststartExecutable;
@ -344,7 +341,7 @@ namespace WinSW
string stopExecutable = this.descriptor.StopExecutable ?? this.descriptor.Executable; string stopExecutable = this.descriptor.StopExecutable ?? this.descriptor.Executable;
// TODO: Redirect logging to Log4Net once https://github.com/kohsuke/winsw/pull/213 is integrated // TODO: Redirect logging to Log4Net once https://github.com/kohsuke/winsw/pull/213 is integrated
this.StartProcess(stopProcess, stopArguments, stopExecutable, null, false); this.StartProcess(stopProcess, stopArguments, stopExecutable, null);
Log.Debug("WaitForProcessToExit " + this.process.Id + "+" + stopProcess.Id); Log.Debug("WaitForProcessToExit " + this.process.Id + "+" + stopProcess.Id);
this.WaitForProcessToExit(this.process); this.WaitForProcessToExit(this.process);
@ -401,7 +398,7 @@ namespace WinSW
sc.SetStatus(this.ServiceHandle, ServiceControllerStatus.Stopped); sc.SetStatus(this.ServiceHandle, ServiceControllerStatus.Stopped);
} }
private void StartProcess(Process processToStart, string arguments, string executable, LogHandler? logHandler, bool redirectStdin) private void StartProcess(Process processToStart, string arguments, string executable, LogHandler? logHandler)
{ {
// Define handler of the completed process // Define handler of the completed process
void OnProcessCompleted(Process process) void OnProcessCompleted(Process process)
@ -443,7 +440,6 @@ namespace WinSW
priority: this.descriptor.Priority, priority: this.descriptor.Priority,
onExited: OnProcessCompleted, onExited: OnProcessCompleted,
logHandler: logHandler, logHandler: logHandler,
redirectStdin: redirectStdin,
hideWindow: this.descriptor.HideWindow); hideWindow: this.descriptor.HideWindow);
} }
@ -452,7 +448,6 @@ namespace WinSW
var info = new ProcessStartInfo(executable, arguments) var info = new ProcessStartInfo(executable, arguments)
{ {
UseShellExecute = false, UseShellExecute = false,
RedirectStandardInput = true,
WorkingDirectory = this.descriptor.WorkingDirectory, WorkingDirectory = this.descriptor.WorkingDirectory,
}; };
@ -475,7 +470,6 @@ namespace WinSW
process.EnableRaisingEvents = true; process.EnableRaisingEvents = true;
} }
process.StandardInput.Close();
return process; return process;
} }
} }