diff --git a/src/Proc/ObservableProcessBase.cs b/src/Proc/ObservableProcessBase.cs index 5ade8de..8a30586 100644 --- a/src/Proc/ObservableProcessBase.cs +++ b/src/Proc/ObservableProcessBase.cs @@ -248,6 +248,7 @@ protected void SendYesForBatPrompt() } //best effort catch (InvalidOperationException) { } + catch (IOException) { } } } diff --git a/tests/Proc.Tests/ControlCTestCases.cs b/tests/Proc.Tests/ControlCTestCases.cs index 964d299..22da4dc 100644 --- a/tests/Proc.Tests/ControlCTestCases.cs +++ b/tests/Proc.Tests/ControlCTestCases.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using System.IO; using FluentAssertions; -using Xunit; namespace ProcNet.Tests { @@ -24,6 +24,7 @@ [SkipOnNonWindowsFact] public void ControlC() seen[0].Should().Be("Written before control+c"); seen[1].Should().Be("Written after control+c"); } + [SkipOnNonWindowsFact] public void ControlCSend() { var args = TestCaseArguments(nameof(ControlC)); @@ -49,7 +50,6 @@ [SkipOnNonWindowsFact] public void ControlCNoWait() args.SendControlCFirst = true; var process = new ObservableProcess(args); - var seen = new List(); process.SubscribeLines(c=> { @@ -62,5 +62,18 @@ [SkipOnNonWindowsFact] public void ControlCNoWait() seen[0].Should().Be("Written before control+c"); } + [SkipOnNonWindowsFact] + public void ControlCIngoredByCmd() { + var args = CmdTestCaseArguments("TrulyLongRunning"); + args.SendControlCFirst = true; + args.WaitForExit = TimeSpan.FromSeconds(2); + + var process = new ObservableProcess(args); + process.SubscribeLines(c => { }); + + Action call = () => process.WaitForCompletion(TimeSpan.FromSeconds(1)); + + call.ShouldNotThrow(); + } } } diff --git a/tests/Proc.Tests/TestsBase.cs b/tests/Proc.Tests/TestsBase.cs index 695ed2c..e155883 100644 --- a/tests/Proc.Tests/TestsBase.cs +++ b/tests/Proc.Tests/TestsBase.cs @@ -26,6 +26,15 @@ private static string GetWorkingDir() return binaryFolder; } + protected static StartArguments CmdTestCaseArguments(string testcase, params string[] args) { + string[] arguments = ["/C", "dotnet", GetDll(), testcase]; + + return new StartArguments("cmd", arguments.Concat(args)) { + WorkingDirectory = GetWorkingDir(), + Timeout = WaitTimeout + }; + } + protected static StartArguments TestCaseArguments(string testcase, params string[] args) { string[] arguments = [GetDll(), testcase];