Skip to content

$? of redirection >, >>, 2>, and 2>> is unexpected. #16033

Closed

Description

@XValue

Prerequisites

Steps to reproduce

$? of redirection >, >>, 2>, and 2>> is unexpected.

Expected behavior

PS> "hello"
hello
PS> "abc" > $null
PS> $?
True
PS>
PS>
PS> 2 + "a"
InvalidArgument: Cannot convert value "a" to type "System.Int32". Error: "Input string was not in a correct format."
PS> "abc" > $null
PS> $?
True

Actual behavior

PS> "hello"
hello
PS> "abc" > $null
PS> $?
True
PS>
PS>
PS> 2 + "a"
InvalidArgument: Cannot convert value "a" to type "System.Int32". Error: "Input string was not in a correct format."
PS> "abc" > $null
PS> $?
False

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


Name                           Value
----                           -----
PSVersion                      7.2.0-preview.9
PSEdition                      Core
GitCommitId                    7.2.0-preview.9
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Bug

Activity

  1. added
    Needs-Triage
    on Sep 1, 2021
  2. vexx32 commented on Sep 1, 2021

    @vexx32
    Collaborator

    I'm seeing the same on the latest preview. I wonder if this is because it's considered a 'pure' expression and thus doesn't set $?? was it an intentional change in this instance?

  3. XValue commented on Sep 1, 2021

    @XValue
    Author

    I don't think it's considered a 'pure' expression.
    PS> "hello"
    hello
    PS> "abc" > C:\1.txt
    Out-File: Access to the path 'C:\1.txt' is denied.
    PS> $?
    False

  4. added
    Issue-Bug
    WG-Engine
    and removed
    Needs-Triage
    on Sep 2, 2021
  5. daxian-dbw commented on Sep 3, 2021

    @daxian-dbw
    Member

    The Engine WG reviewed this issue and agreed this is a bug that should be fixed. Hopefully #16046 will fix it.

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-FixedWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions