From 4d187eb882c7a714050b787911435ea75aaa171d Mon Sep 17 00:00:00 2001
From: NextTurn <45985406+NextTurn@users.noreply.github.com>
Date: Tue, 28 Jul 2020 00:00:00 +0800
Subject: [PATCH] Leave STDIN open
---
src/WinSW.Core/Util/ProcessHelper.cs | 3 ---
src/WinSW/WrapperService.cs | 12 +++---------
2 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/WinSW.Core/Util/ProcessHelper.cs b/src/WinSW.Core/Util/ProcessHelper.cs
index b5a4a03..585a672 100644
--- a/src/WinSW.Core/Util/ProcessHelper.cs
+++ b/src/WinSW.Core/Util/ProcessHelper.cs
@@ -130,7 +130,6 @@ namespace WinSW.Util
/// Working directory
/// Priority
/// Completion callback. If null, the completion won't be monitored
- /// Redirect standard input
/// Log handler. If enabled, logs will be redirected to the process and then reported
public static void StartProcessAndCallbackForExit(
Process processToStart,
@@ -140,7 +139,6 @@ namespace WinSW.Util
string? workingDirectory = null,
ProcessPriorityClass? priority = null,
Action? onExited = null,
- bool redirectStdin = true,
LogHandler? logHandler = null,
bool hideWindow = false)
{
@@ -150,7 +148,6 @@ namespace WinSW.Util
ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory;
ps.CreateNoWindow = hideWindow;
ps.UseShellExecute = false;
- ps.RedirectStandardInput = redirectStdin;
ps.RedirectStandardOutput = logHandler != null;
ps.RedirectStandardError = logHandler != null;
diff --git a/src/WinSW/WrapperService.cs b/src/WinSW/WrapperService.cs
index 60d61b6..549401c 100644
--- a/src/WinSW/WrapperService.cs
+++ b/src/WinSW/WrapperService.cs
@@ -5,7 +5,6 @@ using System.IO;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
-using System.Text.RegularExpressions;
using System.Threading.Tasks;
using log4net;
using WinSW.Extensions;
@@ -282,11 +281,9 @@ namespace WinSW
this.ExtensionManager.FireOnWrapperStarted();
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.process.StandardInput.Close(); // nothing for you to read!
-
try
{
string? poststartExecutable = this.descriptor.PoststartExecutable;
@@ -344,7 +341,7 @@ namespace WinSW
string stopExecutable = this.descriptor.StopExecutable ?? this.descriptor.Executable;
// 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);
this.WaitForProcessToExit(this.process);
@@ -401,7 +398,7 @@ namespace WinSW
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
void OnProcessCompleted(Process process)
@@ -443,7 +440,6 @@ namespace WinSW
priority: this.descriptor.Priority,
onExited: OnProcessCompleted,
logHandler: logHandler,
- redirectStdin: redirectStdin,
hideWindow: this.descriptor.HideWindow);
}
@@ -452,7 +448,6 @@ namespace WinSW
var info = new ProcessStartInfo(executable, arguments)
{
UseShellExecute = false,
- RedirectStandardInput = true,
WorkingDirectory = this.descriptor.WorkingDirectory,
};
@@ -475,7 +470,6 @@ namespace WinSW
process.EnableRaisingEvents = true;
}
- process.StandardInput.Close();
return process;
}
}