Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,21 @@ private void CleanUp()

try
{
// Dispose the process if it's already created
if (_nativeProcess != null)
{
// on Unix, we need to kill the process to ensure it terminates as Dispose() merely
// closes the redirected streams and the processs does not exit on macOS. However,
// on Windows, a winexe like notepad should continue running so we don't want to kill it.
#if UNIX
try
{
_nativeProcess.Kill();
}
catch
{
// Ignore all exception since it is cleanup.
}
#endif
_nativeProcess.Dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Describe 'native commands with pipeline' -tags 'Feature' {
$result[0] | Should -Match "pwsh"
}
}

It 'native command should be killed when pipeline is disposed' -Skip:($IsWindows) {
$yes = (Get-Process 'yes' -ErrorAction Ignore).Count
yes | Select-Object -First 2
(Get-Process 'yes' -ErrorAction Ignore).Count | Should -Be $yes
}
}

Describe "Native Command Processor" -tags "Feature" {
Expand Down