Skip to content

PSNotApplyErrorActionToStderr does not work as expected with ForEach-Object -Parallel #14602

Closed

Description

@aelij

Steps to reproduce

Enable PSNotApplyErrorActionToStderr - no longer needed

$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

Activity

  1. added
    Issue-Question
    on Jan 12, 2021
  2. added
    Issue-Bug
    WG-Engine
    and removed
    Issue-Question
    on Jan 12, 2021
  3. iSazonov commented on Jan 12, 2021

    @iSazonov
    Collaborator

    It works well without $ErrorActionPreference = 'Stop'.

    /cc Paul Higinbotham (@PaulHigin)

  4. aelij commented on Jan 12, 2021

    @aelij
    Author

    It works well without $ErrorActionPreference = 'Stop'.

    Actually it doesn't. Stop only causes execution to continue, but it still creates error records (note the red output). If you remove -Parallel, no error records are created, as expected.

  5. PaulHigin commented on Jan 12, 2021

    @PaulHigin
    Contributor

    This is a known issue. Current session state is not propagated to parallel running sessions. This is currently by design, but there is a work item to address this to some degree.

    #12240

  6. aelij commented on Jan 12, 2021

    @aelij
    Author

    Paul Higinbotham (@PaulHigin) How are experimental features flags related to a session? They are defined in powershell.config.json. Shouldn't every session load it independently?

  7. PaulHigin commented on Jan 12, 2021

    @PaulHigin
    Contributor

    Sorry, I misread the issue. I thought this was about propagating the $ErrorActionPreference built-in variable, and it looks like that is being done. I am not sure about experimental features, but it is likely a similar problem in that it needs to be set in the parallel running sessions.

    Eli Arbel (@aelij) Please add a comment to issue #12240, so that experimental feature enabling is also considered. Then we can close this issue.

  8. aelij commented on Jan 12, 2021

    @aelij
    Author

    I think this should be a different issue.

    This is about reading the correct config inside Parallel, not shared variables/session. It's likely the fix will be different too.

  9. PaulHigin commented on Jan 12, 2021

    @PaulHigin
    Contributor

    It is the same in how the sessions are set up before running in parallel. There is no point in having multiple issues. I'll add a note to that relevant issue and close this one.

  10. 1 remaining item

  11. ghost closed this as completedon Jan 14, 2021
  12. removed
    Resolution-Duplicate
    on Jan 14, 2021
  13. added
    Resolution-No Activity
    on Nov 16, 2023
  14. aelij commented on Nov 21, 2023

    @aelij
    Author

    Bump - still relevant

  15. removed
    Resolution-No Activity
    on Nov 21, 2023
  16. aelij commented on Dec 6, 2023

    @aelij
    Author

    @RandyInMarin

    If the setting in the json file is changed, additional propagation from an active session should use the current session value.

    Are you referring to the experimental flags JSON? That's not relevant anymore.

    This issue is about how -Parallel handles stderr output differently. Just run the sample in the post.

  17. added
    Resolution-No Activity
    on Jun 3, 2024
  18. microsoft-github-policy-service commented on Jun 3, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions