Skip to content

Commit 64bbd38

Browse files
authored
Fix 'The pipe is being closed' IOException when CMD process ignores a Control+C and is stopped. (#19)
1 parent 240084a commit 64bbd38

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/Proc/ObservableProcessBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ protected void SendYesForBatPrompt()
248248
}
249249
//best effort
250250
catch (InvalidOperationException) { }
251+
catch (IOException) { }
251252
}
252253
}
253254

tests/Proc.Tests/ControlCTestCases.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using FluentAssertions;
4-
using Xunit;
55

66
namespace ProcNet.Tests
77
{
@@ -24,6 +24,7 @@ [SkipOnNonWindowsFact] public void ControlC()
2424
seen[0].Should().Be("Written before control+c");
2525
seen[1].Should().Be("Written after control+c");
2626
}
27+
2728
[SkipOnNonWindowsFact] public void ControlCSend()
2829
{
2930
var args = TestCaseArguments(nameof(ControlC));
@@ -49,7 +50,6 @@ [SkipOnNonWindowsFact] public void ControlCNoWait()
4950
args.SendControlCFirst = true;
5051

5152
var process = new ObservableProcess(args);
52-
5353
var seen = new List<string>();
5454
process.SubscribeLines(c=>
5555
{
@@ -62,5 +62,18 @@ [SkipOnNonWindowsFact] public void ControlCNoWait()
6262
seen[0].Should().Be("Written before control+c");
6363
}
6464

65+
[SkipOnNonWindowsFact]
66+
public void ControlCIngoredByCmd() {
67+
var args = CmdTestCaseArguments("TrulyLongRunning");
68+
args.SendControlCFirst = true;
69+
args.WaitForExit = TimeSpan.FromSeconds(2);
70+
71+
var process = new ObservableProcess(args);
72+
process.SubscribeLines(c => { });
73+
74+
Action call = () => process.WaitForCompletion(TimeSpan.FromSeconds(1));
75+
76+
call.ShouldNotThrow<IOException>();
77+
}
6578
}
6679
}

tests/Proc.Tests/TestsBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ private static string GetWorkingDir()
2626
return binaryFolder;
2727
}
2828

29+
protected static StartArguments CmdTestCaseArguments(string testcase, params string[] args) {
30+
string[] arguments = ["/C", "dotnet", GetDll(), testcase];
31+
32+
return new StartArguments("cmd", arguments.Concat(args)) {
33+
WorkingDirectory = GetWorkingDir(),
34+
Timeout = WaitTimeout
35+
};
36+
}
37+
2938
protected static StartArguments TestCaseArguments(string testcase, params string[] args)
3039
{
3140
string[] arguments = [GetDll(), testcase];

0 commit comments

Comments
 (0)