From 1b37248f1b54621b073a7de9a8be08c1e3dc0f48 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Fri, 14 Jul 2017 02:29:22 +0900 Subject: [PATCH 01/19] Fix garbled characters in history view with non-ascii characters --- src/GitHub.Api/Git/Tasks/GitLogTask.cs | 2 +- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 27 ++++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/GitHub.Api/Git/Tasks/GitLogTask.cs b/src/GitHub.Api/Git/Tasks/GitLogTask.cs index e21d00a85..92778ad54 100644 --- a/src/GitHub.Api/Git/Tasks/GitLogTask.cs +++ b/src/GitHub.Api/Git/Tasks/GitLogTask.cs @@ -14,7 +14,7 @@ public GitLogTask(IGitObjectFactory gitObjectFactory, public override string ProcessArguments { - get { return @"log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; } + get { return @"-c i18n.logoutputencoding=utf8 log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; } } } } diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index f929fd96b..8cab945d9 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -78,21 +78,18 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, public void Run() { + Thread thread = null; if (Process.StartInfo.RedirectStandardOutput) { - Process.OutputDataReceived += (s, e) => + thread = new Thread(() => { - //Logger.Trace("OutputData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); - - string encodedData = null; - if (e.Data != null) + string line; + while ((line = Process.StandardOutput.ReadLine()) != null) { - encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data)); + outputProcessor.LineReceived(line); } - outputProcessor.LineReceived(encodedData); - }; + }); } - if (Process.StartInfo.RedirectStandardError) { Process.ErrorDataReceived += (s, e) => @@ -102,11 +99,9 @@ public void Run() // Logger.Trace("ErrorData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); //} - string encodedData = null; if (e.Data != null) { - encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data)); - errors.Add(encodedData); + errors.Add(e.Data); } }; } @@ -133,8 +128,8 @@ public void Run() return; } - if (Process.StartInfo.RedirectStandardOutput) - Process.BeginOutputReadLine(); + if (Process.StartInfo.RedirectStandardOutput && thread != null) + thread.Start(); if (Process.StartInfo.RedirectStandardError) Process.BeginErrorReadLine(); if (Process.StartInfo.RedirectStandardInput) @@ -161,6 +156,10 @@ public void Run() onError?.Invoke(null, String.Join(Environment.NewLine, errors.ToArray())); } } + if (thread != null && thread.ThreadState != System.Threading.ThreadState.Aborted) + { + thread.Abort(); + } onEnd?.Invoke(); } From 334187e7f1ff1da05ffdc3e8161455711c56cb8e Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Tue, 18 Jul 2017 03:17:53 +0900 Subject: [PATCH 02/19] Add null terminator --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 8cab945d9..e8c0878c4 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -88,6 +88,8 @@ public void Run() { outputProcessor.LineReceived(line); } + // null is terminator + outputProcessor.LineReceived(null); }); } if (Process.StartInfo.RedirectStandardError) From 6ee7b857d515484e6092a22c88cf42b998eb2274 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Tue, 18 Jul 2017 03:22:50 +0900 Subject: [PATCH 03/19] Wait for thread termination --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index e8c0878c4..a6ff5ff36 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -131,7 +131,10 @@ public void Run() } if (Process.StartInfo.RedirectStandardOutput && thread != null) + { thread.Start(); + thread.Join(); + } if (Process.StartInfo.RedirectStandardError) Process.BeginErrorReadLine(); if (Process.StartInfo.RedirectStandardInput) From a0d8fcdd747e13d0f13464151be01016a9a7d64b Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Tue, 18 Jul 2017 03:23:57 +0900 Subject: [PATCH 04/19] Add reason not to use Process.OutputDataReceived --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index a6ff5ff36..5c76f0c4d 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -78,6 +78,10 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, public void Run() { + /* + * Process.OutputDataReceived in .NET3.5 has encoding bug + * refer: https://github.com/github-for-unity/Unity/issues/124 + */ Thread thread = null; if (Process.StartInfo.RedirectStandardOutput) { From 298f8f9110a9e4b091157cf910b941166dd088a6 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Tue, 18 Jul 2017 03:19:31 +0900 Subject: [PATCH 05/19] .NET 4.6 has not encoding problem --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 5c76f0c4d..70f499b89 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -78,6 +78,17 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, public void Run() { +#if NET_4_6 + if (Process.StartInfo.RedirectStandardOutput) + { + Process.OutputDataReceived += (s, e) => + { + //Logger.Trace("OutputData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); + + outputProcessor.LineReceived(line); + } + } +#else /* * Process.OutputDataReceived in .NET3.5 has encoding bug * refer: https://github.com/github-for-unity/Unity/issues/124 @@ -96,6 +107,7 @@ public void Run() outputProcessor.LineReceived(null); }); } +#endif if (Process.StartInfo.RedirectStandardError) { Process.ErrorDataReceived += (s, e) => @@ -134,11 +146,16 @@ public void Run() return; } +#if NET_4_6 + if (Process.StartInfo.RedirectStandardOutput) + Process.BeginOutputReadLine(); +#else if (Process.StartInfo.RedirectStandardOutput && thread != null) { thread.Start(); thread.Join(); } +#endif if (Process.StartInfo.RedirectStandardError) Process.BeginErrorReadLine(); if (Process.StartInfo.RedirectStandardInput) @@ -165,10 +182,12 @@ public void Run() onError?.Invoke(null, String.Join(Environment.NewLine, errors.ToArray())); } } +#if (!NET_4_6) if (thread != null && thread.ThreadState != System.Threading.ThreadState.Aborted) { thread.Abort(); } +#endif onEnd?.Invoke(); } From 3168f6d9c0027eed1d5531758c4f315753e13ac8 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Tue, 18 Jul 2017 20:00:41 +0900 Subject: [PATCH 06/19] Read process output asynchronously Since the ReadLine() loop blocks I/O, use Stream::BeginRead instead. --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 126 ++++++++++++++++---- 1 file changed, 100 insertions(+), 26 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 70f499b89..44c5b1700 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -57,6 +57,12 @@ class ProcessWrapper private readonly Action onError; private readonly CancellationToken token; private readonly List errors = new List(); +#if (!NET_4_6) + private byte[] outputBuffer; + private byte[] errorBuffer; + // buffer size refers to https://github.com/Unity-Technologies/mono/blob/unity-5.6-staging/mcs/class/System/System.Diagnostics/Process.cs#L1149-L1157 + const int BufferSize = 8192; +#endif public Process Process { get; } public StreamWriter Input { get; private set; } @@ -74,42 +80,65 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, this.onError = onError; this.token = token; this.Process = process; +#if (!NET_4_6) + this.outputBuffer = new Byte[BufferSize]; + this.errorBuffer = new Byte[BufferSize]; +#endif } public void Run() { -#if NET_4_6 +#if (!NET_4_6) + AsyncCallback outputCallback = null; + AsyncCallback errorCallback = null; + var outputReset = new ManualResetEvent(false); + var errorReset = new ManualResetEvent(false); +#endif if (Process.StartInfo.RedirectStandardOutput) { +#if NET_4_6 Process.OutputDataReceived += (s, e) => { //Logger.Trace("OutputData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); outputProcessor.LineReceived(line); } - } #else - /* - * Process.OutputDataReceived in .NET3.5 has encoding bug - * refer: https://github.com/github-for-unity/Unity/issues/124 - */ - Thread thread = null; - if (Process.StartInfo.RedirectStandardOutput) - { - thread = new Thread(() => + /* + * Process.OutputDataReceived in .NET3.5 has encoding bug + * refer: https://github.com/github-for-unity/Unity/issues/124 + */ + var outputContents = new StringBuilder(); + var outputEncoding = Process.StartInfo.StandardOutputEncoding ?? Console.Out.Encoding; + outputCallback = (r) => { - string line; - while ((line = Process.StandardOutput.ReadLine()) != null) + int bytesRead = Process.StandardOutput.BaseStream.EndRead(r); + if (bytesRead > 0) + { + var encoded = outputEncoding.GetString(outputBuffer, 0, bytesRead); + outputContents.Append(encoded); + Process.StandardOutput.BaseStream.BeginRead(outputBuffer, 0, outputBuffer.Length, outputCallback, Process.StandardOutput); + } + else { - outputProcessor.LineReceived(line); + using (var reader = new StringReader(outputContents.ToString())) + { + string line; + while ((line = reader.ReadLine()) != null) + { + outputProcessor.LineReceived(line); + } + } + // null is terminator + outputProcessor.LineReceived(null); + outputReset.Set(); } - // null is terminator - outputProcessor.LineReceived(null); - }); + }; } #endif if (Process.StartInfo.RedirectStandardError) { +#if NET_4_6 Process.ErrorDataReceived += (s, e) => { //if (e.Data != null) @@ -122,6 +151,32 @@ public void Run() errors.Add(e.Data); } }; +#else + var errorContents = new StringBuilder(); + var errorEncoding = Process.StartInfo.StandardErrorEncoding ?? Console.Out.Encoding; + errorCallback = (r) => + { + int bytesRead = Process.StandardError.BaseStream.EndRead(r); + if (bytesRead > 0) + { + var encoded = errorEncoding.GetString(errorBuffer, 0, bytesRead); + errorContents.Append(encoded); + Process.StandardError.BaseStream.BeginRead(errorBuffer, 0, errorBuffer.Length, errorCallback, Process.StandardError); + } + else + { + using (var reader = new StringReader(errorContents.ToString())) + { + string line; + while ((line = reader.ReadLine()) != null) + { + errors.Add(line); + } + } + errorReset.Set(); + } + }; +#endif } try @@ -146,23 +201,47 @@ public void Run() return; } -#if NET_4_6 if (Process.StartInfo.RedirectStandardOutput) +#if NET_4_6 Process.BeginOutputReadLine(); #else - if (Process.StartInfo.RedirectStandardOutput && thread != null) { - thread.Start(); - thread.Join(); + outputReset.Reset(); + Process.StandardOutput.BaseStream.BeginRead( + outputBuffer, + 0, + outputBuffer.Length, + outputCallback, + Process.StandardOutput + ); } #endif if (Process.StartInfo.RedirectStandardError) +#if NET_4_6 Process.BeginErrorReadLine(); +#else + { + errorReset.Reset(); + Process.StandardError.BaseStream.BeginRead( + errorBuffer, + 0, + errorBuffer.Length, + errorCallback, + Process.StandardError + ); + } +#endif if (Process.StartInfo.RedirectStandardInput) Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false)); onStart?.Invoke(); +#if (!NET_4_6) + if (Process.StartInfo.RedirectStandardOutput) + outputReset.WaitOne(); + if (Process.StartInfo.RedirectStandardError) + errorReset.WaitOne(); +#endif if (Process.StartInfo.CreateNoWindow) { while (!WaitForExit(500)) @@ -182,12 +261,7 @@ public void Run() onError?.Invoke(null, String.Join(Environment.NewLine, errors.ToArray())); } } -#if (!NET_4_6) - if (thread != null && thread.ThreadState != System.Threading.ThreadState.Aborted) - { - thread.Abort(); - } -#endif + onEnd?.Invoke(); } From e229e8e18dfe7fa69e795ce42016327995aea145 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Tue, 18 Jul 2017 20:03:28 +0900 Subject: [PATCH 07/19] Unicode support setting reference from https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support --- src/GitHub.Api/Git/Tasks/GitLogTask.cs | 2 +- src/GitHub.Api/Git/Tasks/GitStatusTask.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub.Api/Git/Tasks/GitLogTask.cs b/src/GitHub.Api/Git/Tasks/GitLogTask.cs index 92778ad54..eeb0f6ebe 100644 --- a/src/GitHub.Api/Git/Tasks/GitLogTask.cs +++ b/src/GitHub.Api/Git/Tasks/GitLogTask.cs @@ -14,7 +14,7 @@ public GitLogTask(IGitObjectFactory gitObjectFactory, public override string ProcessArguments { - get { return @"-c i18n.logoutputencoding=utf8 log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; } + get { return @"-c i18n.logoutputencoding=utf8 -c core.quotepath=false log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; } } } } diff --git a/src/GitHub.Api/Git/Tasks/GitStatusTask.cs b/src/GitHub.Api/Git/Tasks/GitStatusTask.cs index 13afb9389..1186f364a 100644 --- a/src/GitHub.Api/Git/Tasks/GitStatusTask.cs +++ b/src/GitHub.Api/Git/Tasks/GitStatusTask.cs @@ -14,7 +14,7 @@ public GitStatusTask(IGitObjectFactory gitObjectFactory, public override string ProcessArguments { - get { return "status -b -u --ignored --porcelain"; } + get { return "-c i18n.logoutputencoding=utf8 -c core.quotepath=false status -b -u --ignored --porcelain"; } } public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } } } From 8950cff1e9f9fc596b663c8d491dbf3b2cc3662c Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Sat, 22 Jul 2017 19:19:51 +0900 Subject: [PATCH 08/19] Overwrite i18n.commitencoding to unify character encoding with utf8 --- src/GitHub.Api/Git/Tasks/GitCommitTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub.Api/Git/Tasks/GitCommitTask.cs b/src/GitHub.Api/Git/Tasks/GitCommitTask.cs index c532ce5d3..7ba24cbca 100644 --- a/src/GitHub.Api/Git/Tasks/GitCommitTask.cs +++ b/src/GitHub.Api/Git/Tasks/GitCommitTask.cs @@ -13,7 +13,7 @@ public GitCommitTask(string message, string body, { Guard.ArgumentNotNullOrWhiteSpace(message, "message"); - arguments = "commit "; + arguments = "-c i18n.commitencoding=utf8 commit "; arguments += String.Format(" -m \"{0}", message); if (!String.IsNullOrEmpty(body)) arguments += String.Format("{0}{1}", Environment.NewLine, body); From 05fc0c3fc0b1af8c66ec431a2aec01bc214d3eed Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Thu, 3 Aug 2017 01:52:00 +0900 Subject: [PATCH 09/19] Remove all the #if/#endif with NET_4_6 --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 42 +-------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 44c5b1700..3acb2c394 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -57,12 +57,10 @@ class ProcessWrapper private readonly Action onError; private readonly CancellationToken token; private readonly List errors = new List(); -#if (!NET_4_6) private byte[] outputBuffer; private byte[] errorBuffer; // buffer size refers to https://github.com/Unity-Technologies/mono/blob/unity-5.6-staging/mcs/class/System/System.Diagnostics/Process.cs#L1149-L1157 const int BufferSize = 8192; -#endif public Process Process { get; } public StreamWriter Input { get; private set; } @@ -80,30 +78,19 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, this.onError = onError; this.token = token; this.Process = process; -#if (!NET_4_6) this.outputBuffer = new Byte[BufferSize]; this.errorBuffer = new Byte[BufferSize]; -#endif } public void Run() { -#if (!NET_4_6) AsyncCallback outputCallback = null; AsyncCallback errorCallback = null; var outputReset = new ManualResetEvent(false); var errorReset = new ManualResetEvent(false); -#endif + if (Process.StartInfo.RedirectStandardOutput) { -#if NET_4_6 - Process.OutputDataReceived += (s, e) => - { - //Logger.Trace("OutputData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); - - outputProcessor.LineReceived(line); - } -#else /* * Process.OutputDataReceived in .NET3.5 has encoding bug * refer: https://github.com/github-for-unity/Unity/issues/124 @@ -135,23 +122,8 @@ public void Run() } }; } -#endif if (Process.StartInfo.RedirectStandardError) { -#if NET_4_6 - Process.ErrorDataReceived += (s, e) => - { - //if (e.Data != null) - //{ - // Logger.Trace("ErrorData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); - //} - - if (e.Data != null) - { - errors.Add(e.Data); - } - }; -#else var errorContents = new StringBuilder(); var errorEncoding = Process.StartInfo.StandardErrorEncoding ?? Console.Out.Encoding; errorCallback = (r) => @@ -176,7 +148,6 @@ public void Run() errorReset.Set(); } }; -#endif } try @@ -202,9 +173,6 @@ public void Run() } if (Process.StartInfo.RedirectStandardOutput) -#if NET_4_6 - Process.BeginOutputReadLine(); -#else { outputReset.Reset(); Process.StandardOutput.BaseStream.BeginRead( @@ -215,11 +183,7 @@ public void Run() Process.StandardOutput ); } -#endif if (Process.StartInfo.RedirectStandardError) -#if NET_4_6 - Process.BeginErrorReadLine(); -#else { errorReset.Reset(); Process.StandardError.BaseStream.BeginRead( @@ -230,18 +194,16 @@ public void Run() Process.StandardError ); } -#endif if (Process.StartInfo.RedirectStandardInput) Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false)); onStart?.Invoke(); -#if (!NET_4_6) if (Process.StartInfo.RedirectStandardOutput) outputReset.WaitOne(); if (Process.StartInfo.RedirectStandardError) errorReset.WaitOne(); -#endif + if (Process.StartInfo.CreateNoWindow) { while (!WaitForExit(500)) From 83bb4c5e2e8704199ccba1173b42cabd6227c85f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 10 Aug 2017 18:57:15 -0400 Subject: [PATCH 10/19] Reading stream inline while leaving input to be routed via event --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 87 +++++++++++---------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index f929fd96b..2ac570e58 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -78,37 +78,19 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, public void Run() { - if (Process.StartInfo.RedirectStandardOutput) + if (!Process.StartInfo.RedirectStandardOutput) { - Process.OutputDataReceived += (s, e) => - { - //Logger.Trace("OutputData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); - - string encodedData = null; - if (e.Data != null) - { - encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data)); - } - outputProcessor.LineReceived(encodedData); - }; + throw new ArgumentException("Process must RedirectStandardOutput"); } - if (Process.StartInfo.RedirectStandardError) + if (!Process.StartInfo.RedirectStandardError) { - Process.ErrorDataReceived += (s, e) => - { - //if (e.Data != null) - //{ - // Logger.Trace("ErrorData \"" + (e.Data == null ? "'null'" : e.Data) + "\""); - //} + throw new ArgumentException("Process must RedirectStandardError"); + } - string encodedData = null; - if (e.Data != null) - { - encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data)); - errors.Add(encodedData); - } - }; + if (!Process.StartInfo.CreateNoWindow) + { + throw new ArgumentException("Process must CreateNoWindow"); } try @@ -133,34 +115,55 @@ public void Run() return; } - if (Process.StartInfo.RedirectStandardOutput) - Process.BeginOutputReadLine(); - if (Process.StartInfo.RedirectStandardError) - Process.BeginErrorReadLine(); if (Process.StartInfo.RedirectStandardInput) Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false)); onStart?.Invoke(); - if (Process.StartInfo.CreateNoWindow) + var outputStream = Process.StandardOutput; + var line = outputStream.ReadLine(); + while (line != null) { - while (!WaitForExit(500)) + outputProcessor.LineReceived(line); + + if (token.IsCancellationRequested) { - if (token.IsCancellationRequested) - { - if (!Process.HasExited) - Process.Kill(); - Process.Close(); - onEnd?.Invoke(); - token.ThrowIfCancellationRequested(); - } + if (!Process.HasExited) + Process.Kill(); + + Process.Close(); + onEnd?.Invoke(); + token.ThrowIfCancellationRequested(); } - if (Process.ExitCode != 0 && errors.Count > 0) + line = outputStream.ReadLine(); + } + outputProcessor.LineReceived(null); + + var errorStream = Process.StandardError; + var errorLine = errorStream.ReadLine(); + while (errorLine != null) + { + errors.Add(errorLine); + + if (token.IsCancellationRequested) { - onError?.Invoke(null, String.Join(Environment.NewLine, errors.ToArray())); + if (!Process.HasExited) + Process.Kill(); + + Process.Close(); + onEnd?.Invoke(); + token.ThrowIfCancellationRequested(); } + + errorLine = errorStream.ReadLine(); } + + if (Process.ExitCode != 0 && errors.Count > 0) + { + onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray())); + } + onEnd?.Invoke(); } From 5bef6a2eac2725e4f79f1837688008a018969884 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 11:03:01 -0400 Subject: [PATCH 11/19] Mixing both changes after the merge --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 57 ++++++++++++++++----- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 2ac570e58..a04034d43 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -56,7 +57,6 @@ class ProcessWrapper private readonly Action onEnd; private readonly Action onError; private readonly CancellationToken token; - private readonly List errors = new List(); public Process Process { get; } public StreamWriter Input { get; private set; } @@ -110,7 +110,7 @@ public void Run() sb.AppendFormat("{0}:{1}", env, Process.StartInfo.EnvironmentVariables[env]); sb.AppendLine(); } - onError?.Invoke(ex, String.Format("{0} {1}", ex.Message, sb.ToString())); + onError?.Invoke(ex, $"{ex.Message} {sb}"); onEnd?.Invoke(); return; } @@ -120,11 +120,19 @@ public void Run() onStart?.Invoke(); - var outputStream = Process.StandardOutput; - var line = outputStream.ReadLine(); - while (line != null) + // buffer size refers to https://github.com/Unity-Technologies/mono/blob/unity-5.6-staging/mcs/class/System/System.Diagnostics/Process.cs#L1149-L1157 + const int bufferSize = 8182; + + var outputStream = Process.StandardOutput.BaseStream; + var outputBuffer = new byte[bufferSize]; + var outputEncoding = Process.StartInfo.StandardOutputEncoding ?? Console.Out.Encoding; + var outputStringBuilder = new StringBuilder(); + + var bytesRead = outputStream.Read(outputBuffer, 0, bufferSize); + while (bytesRead > 0) { - outputProcessor.LineReceived(line); + var encoded = outputEncoding.GetString(outputBuffer, 0, bytesRead); + outputStringBuilder.Append(encoded); if (token.IsCancellationRequested) { @@ -136,15 +144,29 @@ public void Run() token.ThrowIfCancellationRequested(); } - line = outputStream.ReadLine(); + bytesRead = outputStream.Read(outputBuffer, 0, bufferSize); + } + + var lines = outputStringBuilder.ToString().Split(new[] { "\n" }, StringSplitOptions.None); + //All but the last line, which will always be empty + for (var index = 0; index < lines.Length - 1; index++) + { + var line = lines[index]; + outputProcessor.LineReceived(line); } + outputProcessor.LineReceived(null); - var errorStream = Process.StandardError; - var errorLine = errorStream.ReadLine(); - while (errorLine != null) + var errorStream = Process.StandardError.BaseStream; + var errorBuffer = new byte[bufferSize]; + var errorEncoding = Process.StartInfo.StandardOutputEncoding ?? Console.Out.Encoding; + var errorStringBuilder = new StringBuilder(); + + bytesRead = errorStream.Read(errorBuffer, 0, bufferSize); + while (bytesRead > 0) { - errors.Add(errorLine); + var encoded = errorEncoding.GetString(outputBuffer, 0, bytesRead); + errorStringBuilder.Append(encoded); if (token.IsCancellationRequested) { @@ -156,12 +178,19 @@ public void Run() token.ThrowIfCancellationRequested(); } - errorLine = errorStream.ReadLine(); + bytesRead = errorStream.Read(errorBuffer, 0, bufferSize); + } + + var errors = errorStringBuilder.ToString().Split(new[] { "\n" }, StringSplitOptions.None).ToArray(); + if (errors.Length > 1) + { + //All but the last line, which will always be empty + errors = errors.Take(errors.Length - 1).ToArray(); } - if (Process.ExitCode != 0 && errors.Count > 0) + if (Process.ExitCode != 0 && errors.Length > 0) { - onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray())); + onError?.Invoke(null, string.Join(Environment.NewLine, errors)); } onEnd?.Invoke(); From d4fa23d97f108a172b16346057b5003aca0c4ca9 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 11:14:03 -0400 Subject: [PATCH 12/19] Removing unused method --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index a04034d43..9ea6c7590 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -195,20 +195,6 @@ public void Run() onEnd?.Invoke(); } - - private bool WaitForExit(int milliseconds) - { - //Logger.Debug("WaitForExit - time: {0}ms", milliseconds); - - // Workaround for a bug in which some data may still be processed AFTER this method returns true, thus losing the data. - // http://connect.microsoft.com/VisualStudio/feedback/details/272125/waitforexit-and-waitforexit-int32-provide-different-and-undocumented-implementations - bool waitSucceeded = Process.WaitForExit(milliseconds); - if (waitSucceeded) - { - Process.WaitForExit(); - } - return waitSucceeded; - } } /// From 02326519defbbb851b434faf5960e5c2701a8cbb Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 12:08:44 -0400 Subject: [PATCH 13/19] Fixing unit tests --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 9ea6c7590..a3a726fa5 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -147,7 +147,7 @@ public void Run() bytesRead = outputStream.Read(outputBuffer, 0, bufferSize); } - var lines = outputStringBuilder.ToString().Split(new[] { "\n" }, StringSplitOptions.None); + var lines = outputStringBuilder.ToString().Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); //All but the last line, which will always be empty for (var index = 0; index < lines.Length - 1; index++) { @@ -159,13 +159,13 @@ public void Run() var errorStream = Process.StandardError.BaseStream; var errorBuffer = new byte[bufferSize]; - var errorEncoding = Process.StartInfo.StandardOutputEncoding ?? Console.Out.Encoding; + var errorEncoding = Process.StartInfo.StandardErrorEncoding ?? Console.Error.Encoding; var errorStringBuilder = new StringBuilder(); bytesRead = errorStream.Read(errorBuffer, 0, bufferSize); while (bytesRead > 0) { - var encoded = errorEncoding.GetString(outputBuffer, 0, bytesRead); + var encoded = errorEncoding.GetString(errorBuffer, 0, bytesRead); errorStringBuilder.Append(encoded); if (token.IsCancellationRequested) @@ -181,7 +181,7 @@ public void Run() bytesRead = errorStream.Read(errorBuffer, 0, bufferSize); } - var errors = errorStringBuilder.ToString().Split(new[] { "\n" }, StringSplitOptions.None).ToArray(); + var errors = errorStringBuilder.ToString().Split(new[] { "\r\n", "\n" }, StringSplitOptions.None).ToArray(); if (errors.Length > 1) { //All but the last line, which will always be empty From 00ed6f1c1a1e8f9f57aadcef26ce855cf252ddfa Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 11:15:44 -0400 Subject: [PATCH 14/19] Adding NewlineSplitStringBuilder --- src/GitHub.Api/GitHub.Api.csproj | 1 + .../Helpers/NewlineSplitStringBuilder.cs | 57 +++++++++++++++++++ src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 18 ++++-- .../Helpers/NewlineSplitStringBuilderTests.cs | 40 +++++++++++++ src/tests/UnitTests/UnitTests.csproj | 1 + 5 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 src/GitHub.Api/Helpers/NewlineSplitStringBuilder.cs create mode 100644 src/tests/UnitTests/Helpers/NewlineSplitStringBuilderTests.cs diff --git a/src/GitHub.Api/GitHub.Api.csproj b/src/GitHub.Api/GitHub.Api.csproj index 5cb3dc3b3..a4b3ca2e7 100644 --- a/src/GitHub.Api/GitHub.Api.csproj +++ b/src/GitHub.Api/GitHub.Api.csproj @@ -105,6 +105,7 @@ + diff --git a/src/GitHub.Api/Helpers/NewlineSplitStringBuilder.cs b/src/GitHub.Api/Helpers/NewlineSplitStringBuilder.cs new file mode 100644 index 000000000..df648482e --- /dev/null +++ b/src/GitHub.Api/Helpers/NewlineSplitStringBuilder.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace GitHub.Unity.Helpers +{ + class NewlineSplitStringBuilder + { + private StringBuilder builder; + + public string[] Append(string value) + { + if (value == null) + { + var singleResult = builder?.ToString(); + if (singleResult == null) + { + return new string[0]; + } + return new[] { singleResult }; + } + + var splitValues = value.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); + + if (splitValues.Length == 0) + { + throw new ArgumentOutOfRangeException(); + } + + if (builder == null) + { + builder = new StringBuilder(); + } + + builder.Append(splitValues[0]); + + if (splitValues.Length == 1) + { + return new string[0]; + } + + var results = new string[splitValues.Length - 1]; + results[0] = builder.ToString(); + + for (var index = 1; index < splitValues.Length - 1; index++) + { + results[index] = splitValues[index]; + } + + builder = new StringBuilder(splitValues[splitValues.Length - 1]); + + return results; + } + } +} + diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index a3a726fa5..08ada92e4 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using GitHub.Unity.Helpers; namespace GitHub.Unity { @@ -126,13 +127,18 @@ public void Run() var outputStream = Process.StandardOutput.BaseStream; var outputBuffer = new byte[bufferSize]; var outputEncoding = Process.StartInfo.StandardOutputEncoding ?? Console.Out.Encoding; - var outputStringBuilder = new StringBuilder(); + var splitStringbuilder = new NewlineSplitStringBuilder(); + string[] splitLines = null; var bytesRead = outputStream.Read(outputBuffer, 0, bufferSize); while (bytesRead > 0) { var encoded = outputEncoding.GetString(outputBuffer, 0, bytesRead); - outputStringBuilder.Append(encoded); + splitLines = splitStringbuilder.Append(encoded); + foreach (var splitLine in splitLines) + { + outputProcessor.LineReceived(splitLine); + } if (token.IsCancellationRequested) { @@ -147,12 +153,12 @@ public void Run() bytesRead = outputStream.Read(outputBuffer, 0, bufferSize); } - var lines = outputStringBuilder.ToString().Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); + splitLines = splitStringbuilder.Append(null); //All but the last line, which will always be empty - for (var index = 0; index < lines.Length - 1; index++) + for (var index = 0; index < splitLines.Length - 1; index++) { - var line = lines[index]; - outputProcessor.LineReceived(line); + var splitLine = splitLines[index]; + outputProcessor.LineReceived(splitLine); } outputProcessor.LineReceived(null); diff --git a/src/tests/UnitTests/Helpers/NewlineSplitStringBuilderTests.cs b/src/tests/UnitTests/Helpers/NewlineSplitStringBuilderTests.cs new file mode 100644 index 000000000..fdf9cf510 --- /dev/null +++ b/src/tests/UnitTests/Helpers/NewlineSplitStringBuilderTests.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using FluentAssertions; +using GitHub.Unity.Helpers; +using NUnit.Framework; + +namespace UnitTests +{ + [TestFixture] + public class NewlineSplitStringBuilderTests + { + public static TestCaseData[] GetNewlineSplitTestData() + { + return new[] { + new TestCaseData(new string[] {null}, new string[0]).SetName("Null returns nothing"), + new TestCaseData(new string[] { $"ASDF{Environment.NewLine}Hello", null}, new[] {"ASDF", "Hello"}).SetName("Can split whole string"), + new TestCaseData(new string[] { $"ASDF", $"{Environment.NewLine}Hello", null}, new[] {"ASDF", "Hello"}).SetName("Can split string with second beginning newline"), + new TestCaseData(new string[] { $"ASDF{Environment.NewLine}", "Hello", null}, new[] {"ASDF", "Hello"}).SetName("Can split string with first ending newline"), + new TestCaseData(new string[] { $"AS", $"DF{Environment.NewLine}Hello", null}, new[] {"ASDF", "Hello"}).SetName("Can split string with newline contained in second"), + }; + } + + [TestCaseSource("GetNewlineSplitTestData")] + public void NewlineSplitStringBuilderTest(string[] expectedInputs, string[] expectedOutputs) + { + var results = new List(); + var newlineSplitStringBuilder = new NewlineSplitStringBuilder(); + foreach (var expectedInput in expectedInputs) + { + var output = newlineSplitStringBuilder.Append(expectedInput); + if (output != null) + { + results.AddRange(output); + } + } + + results.ShouldAllBeEquivalentTo(expectedOutputs); + } + } +} \ No newline at end of file diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index 1e6b7c2c8..80e9a10c4 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -80,6 +80,7 @@ + From 5aeb27504fc3d8f5d1b2b9d065da280348170b58 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 12:32:01 -0400 Subject: [PATCH 15/19] Fixing conditionals --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 88 ++++++++++----------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 2ac570e58..1007c811d 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -78,21 +78,6 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor, public void Run() { - if (!Process.StartInfo.RedirectStandardOutput) - { - throw new ArgumentException("Process must RedirectStandardOutput"); - } - - if (!Process.StartInfo.RedirectStandardError) - { - throw new ArgumentException("Process must RedirectStandardError"); - } - - if (!Process.StartInfo.CreateNoWindow) - { - throw new ArgumentException("Process must CreateNoWindow"); - } - try { Process.Start(); @@ -120,48 +105,57 @@ public void Run() onStart?.Invoke(); - var outputStream = Process.StandardOutput; - var line = outputStream.ReadLine(); - while (line != null) + if (Process.StartInfo.CreateNoWindow) { - outputProcessor.LineReceived(line); - - if (token.IsCancellationRequested) + if (Process.StartInfo.RedirectStandardOutput) { - if (!Process.HasExited) - Process.Kill(); + var outputStream = Process.StandardOutput; + var line = outputStream.ReadLine(); + while (line != null) + { + outputProcessor.LineReceived(line); - Process.Close(); - onEnd?.Invoke(); - token.ThrowIfCancellationRequested(); - } + if (token.IsCancellationRequested) + { + if (!Process.HasExited) + Process.Kill(); - line = outputStream.ReadLine(); - } - outputProcessor.LineReceived(null); + Process.Close(); + onEnd?.Invoke(); + token.ThrowIfCancellationRequested(); + } - var errorStream = Process.StandardError; - var errorLine = errorStream.ReadLine(); - while (errorLine != null) - { - errors.Add(errorLine); + line = outputStream.ReadLine(); + } + outputProcessor.LineReceived(null); + } - if (token.IsCancellationRequested) + if (!Process.StartInfo.RedirectStandardError) { - if (!Process.HasExited) - Process.Kill(); + var errorStream = Process.StandardError; + var errorLine = errorStream.ReadLine(); + while (errorLine != null) + { + errors.Add(errorLine); - Process.Close(); - onEnd?.Invoke(); - token.ThrowIfCancellationRequested(); - } + if (token.IsCancellationRequested) + { + if (!Process.HasExited) + Process.Kill(); - errorLine = errorStream.ReadLine(); - } + Process.Close(); + onEnd?.Invoke(); + token.ThrowIfCancellationRequested(); + } - if (Process.ExitCode != 0 && errors.Count > 0) - { - onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray())); + errorLine = errorStream.ReadLine(); + } + + if (Process.ExitCode != 0 && errors.Count > 0) + { + onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray())); + } + } } onEnd?.Invoke(); From d12c1434772cc6e442b6b0c0c4ac3f40a4476d87 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 12:48:22 -0400 Subject: [PATCH 16/19] Fixing error redirection --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 1007c811d..e1b9184e8 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -56,7 +56,6 @@ class ProcessWrapper private readonly Action onEnd; private readonly Action onError; private readonly CancellationToken token; - private readonly List errors = new List(); public Process Process { get; } public StreamWriter Input { get; private set; } @@ -103,8 +102,9 @@ public void Run() if (Process.StartInfo.RedirectStandardInput) Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false)); - onStart?.Invoke(); + var errors = new List(); + onStart?.Invoke(); if (Process.StartInfo.CreateNoWindow) { if (Process.StartInfo.RedirectStandardOutput) @@ -130,7 +130,7 @@ public void Run() outputProcessor.LineReceived(null); } - if (!Process.StartInfo.RedirectStandardError) + if (Process.StartInfo.RedirectStandardError) { var errorStream = Process.StandardError; var errorLine = errorStream.ReadLine(); From f828b6ed83e7cf85b11b3aca5c13168fe62cb150 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 12:53:50 -0400 Subject: [PATCH 17/19] Fixing error --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index d342331f5..7dbf0a13b 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -104,8 +104,6 @@ public void Run() if (Process.StartInfo.RedirectStandardInput) Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false)); - var errors = new List(); - onStart?.Invoke(); if (Process.StartInfo.CreateNoWindow) { From 89fba73ec6ec8a8d17f02dff3c4deb5f04c1f3a6 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 11 Aug 2017 13:02:18 -0400 Subject: [PATCH 18/19] Removing DoNotRunOnAppVeyor attribute --- .../IntegrationTests/Process/ProcessManagerIntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs b/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs index 77c34ff29..20e81b96b 100644 --- a/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs +++ b/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs @@ -81,7 +81,7 @@ public async Task LogEntriesTest() }); } - [Test, Category("DoNotRunOnAppVeyor")] + [Test] public async Task RussianLogEntriesTest() { await Initialize(TestRepoMasterCleanUnsynchronizedRussianLanguage); From c9109fac44199928a9c088be385afddd3237efa0 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Koga Date: Sun, 13 Aug 2017 23:19:51 +0900 Subject: [PATCH 19/19] Remove redundant null check --- src/GitHub.Api/NewTaskSystem/ProcessTask.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs index 7dbf0a13b..b233a9bdc 100644 --- a/src/GitHub.Api/NewTaskSystem/ProcessTask.cs +++ b/src/GitHub.Api/NewTaskSystem/ProcessTask.cs @@ -114,7 +114,7 @@ public void Run() { var outputStream = Process.StandardOutput.BaseStream; var outputBuffer = new byte[bufferSize]; - var outputEncoding = Process.StartInfo.StandardOutputEncoding ?? Console.Out.Encoding; + var outputEncoding = Process.StartInfo.StandardOutputEncoding; var splitStringbuilder = new NewlineSplitStringBuilder(); string[] splitLines = null; @@ -156,7 +156,7 @@ public void Run() { var errorStream = Process.StandardError.BaseStream; var errorBuffer = new byte[bufferSize]; - var errorEncoding = Process.StartInfo.StandardErrorEncoding ?? Console.Error.Encoding; + var errorEncoding = Process.StartInfo.StandardErrorEncoding; var errorStringBuilder = new StringBuilder(); var bytesRead = errorStream.Read(errorBuffer, 0, bufferSize);