PSNotApplyErrorActionToStderr does not work as expected with ForEach-Object -Parallel
See original GitHub issueSteps to reproduce
Enable - no longer neededPSNotApplyErrorActionToStderr
$ErrorActionPreference = 'Stop'
@(1,2,3) | ForEach-Object -Parallel { cmd.exe /c "echo $_ >&2" }
Expected behavior
Process all records, with no error records produced:
1
2
3
Actual behavior
Stops after first record, produces an error record for native command stderr:
1 # in red
Environment data
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.20206
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Powershell 7 -> ForEach -Parallel in a Function does not ...
1 Answer. The problem here is that threads running in parallel have to alter the same array. There are methods to make that...
Read more >PowerShell ForEach-Object Parallel Feature
Here script is run on the local machine within the same process but on separate threads. This new feature uses the third method...
Read more >ForEach-Object - Module: Microsoft.PowerShell.Core
The ForEach-Object cmdlet performs an operation on each item in a collection of input objects. The input objects can be piped to the...
Read more >Foreach vs. ForEach-Object -Parallel : r/PowerShell
Hi Guy's I have been searching high and low on this seemingly very simple Foreach loop I have been playing with PowerShell 7...
Read more >Error with foreach-object -parallel : r/PowerShell
I think the problem is that the -parallel keyword makes everything inside the loop {} run in a different parallel universe where they...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@PaulHigin I’ve investigated it a bit, and it doesn’t seem that the issue is about experimental features at all:
yields:
I think the problem is in
NativeCommandProcessor
and how it handles output from background processes. So it should work regardless of the suggested-UseCurrentState
.This code gets executed only in parallel:
https://github.com/PowerShell/PowerShell/blob/4a09585fe72c3679e23a1aa047b23ac827609c55/src/System.Management.Automation/engine/NativeCommandProcessor.cs#L657-L673
So please reopen as it’s definitely unrelated to the other issue.
This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes.