The latest news, powershell, more than 10 years of cancer has been cured!
Q: What is cancer?
Answer:
powershell has always had a feature that its pipeline will pass objects, please see:
'abc' | ForEach-Object {$_.toupper()} #Return to ABC,
what it passes through the pipeline is [string object]. It will force the [content] on the left side of the pipeline to be objectified. This caused [binary data to be piped] problematic.
Common problem scenarios are: the image downloaded by the pipeline is damaged; the compressed program is damaged through the pipeline; the binary program fails to be delivered through the pipeline import, etc.
Example:
curl.exe https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png > a:\pscode\TEMP_2023\temp152\b.png
The size of the output image is different from the image saved as on the web page. The content is also broken.
About the fixed version: psv7.4-preview4
I personally tested the above commands in psv7.4-preview4. The downloaded file is exactly the same as the file I saved using the web page.
It is recommended to go to the official website, download and install psv7.4-preview4:
https://github.com/PowerShell/PowerShell/releases
Q: Which pipelines are related?
Answer: It is related to [|], [>].
Q: For the old version lower than psv7.4-preview4, how to solve this cancer?
Answer: It is lower than psv7.4-preview4, which does not solve this cancer.
The mitigation method is: use cmd /c, or bash -c in powershell. For example:
cmd /c "curl.exe https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png > a:\pscode\TEMP_2023\temp152\c.png"
About 10 years:
https://github.com/PowerShell/PowerShell/issues/1908
The above issue was submitted 7 years ago, but it is more than 7 years. This problem has always existed before powershell was not open source. Even more than 15 years!
Related Links:
https://github.com/PowerShell/PowerShell/issues/1908
https://github.com/MicrosoftDocs/PowerShell-Docs/issues/10134
https://github.com/PowerShell/PowerShell/pull/17857
This proves that there is nothing impossible, only unexpected. If you love .net, you should contribute more to powershell. Don't always think about whoring for nothing.
---Thank you for watching, end---