Skip to content

Can not overwrite files in the pipeline. Is it by design? #9782

@mkht

Description

@mkht

When I tried to read a file using a pipeline, edit the contents, and save it, I got unexpected behavior.
Is this correct behavior by design ?

# Create a text file for testing
PS> 'A' | Out-File -FilePath C:\test.txt

# Read file , modified, overwrite
PS> Get-Content -Path C:\test.txt -Raw | ForEach-Object {$_ + 'B'} | Out-File -FilePath C:\test.txt

# I expect that the output is 'AB', but it outputs nothing
PS> Get-Content -Path C:\test.txt -Raw

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions