Skip to content

PWSH 7.1.3 fails with exit code 1 when stderr is redirected to stdout #1076

Open
@EduardSergeev

Description

@EduardSergeev

Describe the bug
When pwsh (latest: v7.1.3) action on Windows contains stderr -> stdout redirection (e.g.: a simple 2>&1) the action fails with ExitCode 1

To Reproduce
Simply add the following line to windows-2019 action:

- name: STDERR redirection test
  run: $E = $(Write-Error "oops" 2>&1)

Expected behavior

$E = $(Write-Error "oops" 2>&1)

should not cause the build to fail and $E variable should be assigned the value Write-Error: oops

Runner Version and Platform

Current runner version: '2.278.0'
Operating System
  Microsoft Windows Server 2019
  10.0.17763
  Datacenter
Virtual Environment
  Environment: windows-2019
  Version: 20210425.1
  Included Software: https://github.com/actions/virtual-environments/blob/win19/20210425.1/images/win/Windows2019-Readme.md
  Image Release: https://github.com/actions/virtual-environments/releases/tag/win19%2F20210425.1

What's not working?

Run $E = $(Write-Error "oops" 2>&1)
  $E = $(Write-Error "oops" 2>&1)
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
Write-Error: oops
Error: Process completed with exit code 1.

Job Log Output

Run $E = $(Write-Error "oops" 2>&1)
  $E = $(Write-Error "oops" 2>&1)
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
Write-Error: oops
Error: Process completed with exit code 1.

NB: This is different from #169
The code example from #169 :

run: |
  npm ping
  npm ping
  npm ping

does work with the latest version of the runner but 2>&1 does not.

When $E = $(Write-Error "oops" 2>&1) is executed in my local pwsh it works as expected:

PS \> $E = $(Write-Error "oops" 2>&1)
PS \> $lastExitCode
0
PS \> $E
Write-Error: oops

but fails with ExitCode 1 when executed as a part of github action. Both, my pwsh and github action pwsh seem to be of the same version: 7.1.3.
Combined test with version included:

- name: STDERR redirection test
  run: |
    $host.Version
    npm ping
    npm ping
    npm ping
    $E = $(Write-Error "oops" 2>&1)

outputs:

Run $host.Version
  $host.Version
  npm ping
  npm ping
  npm ping
  $E = $(Write-Error "oops" 2>&1)
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"

Major  Minor  Build  Revision
-----  -----  -----  --------
7      1      3      -1
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.527ms
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.277ms
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.269ms
Write-Error: oops
Error: Process completed with exit code 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions