-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not overwrite files in the pipeline. Is it by design? #9782
Comments
Yeah this is what you can call by design. Because The short solution is to force all the input to be pulled before sending it along the pipe; this can be done pretty simply with some parentheses: $Path = 'C:\Test.txt'
'A' | Set-Content -Path $Path
(Get-Content -Path $Path -Raw) | ForEach-Object { $_ + 'B' } | Set-Content -Path $Path
Get-Content -Path $Path -Raw Given the behaviour of |
@vexx32 This is a little off topic but this is a great example of why it'd be nice if commands were disposed directly after |
@SeeminglyScience Good point! I guess this will be a bit easier moving forward. I have a couple PRs to put in first, though. 😄 |
Thanks @vexx32 |
Of course! 😄 |
@vexx32 Please open new tracking issue if you plan to pull a fix. |
@iSazonov a true fix is pretty dicey but some of the changes necessary for #9900 will make this much less tricky to handle, as the file handle should be closed as soon as the command is done with its output. I'll have to see if that actually is the case or there needs to be changes in |
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 ?
The text was updated successfully, but these errors were encountered: