PowerShell / PowerShell Public
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
Don’t parse the pipeline as text when it is directed from an EXE to another EXE or file. Keep the bytes as-is. #1908
Comments
|
Maybe add a cmdlet/operator to call native command and get its raw output (as a byte array / stream?), something like this: # Consider ^& operator is an alias for Get-CommandRawOutputStream; this is just an example syntax
$output = ^& curl.exe http://whatever/a.png # $output now is a byte array or stream
$output > C:\Temp\file.png # file.png now is a valid image file
# This should be valid, too:
^& curl.exe http://whatever/a.png > C:\Temp\file.pngThis opens an opportunity for some additional usage patterns (you can put this raw content into variables, and pipe raw content from native commands to managed cmdlets). |
|
But maybe we could add a special kind of redirection operator (like $output = curl.exe http://whatever/a.png %>&1
$output > C:\Temp\file.png
# Or even this:
curl.exe http://whatever/a.png %> C:\Temp\file.png # which is just awesomeOverall: I don't think that this kind of redirection should be tied to only native commands or some limited list of usage patterns (e.g. |
|
@ForNeVeR My proposal is that:
|
|
@be5invis okay, it seems like this proposal also supports all the relevant use cases I can imagine. |
|
Shouldn't this open up an RFC since this is a breaking change (changes the observed behaviour)? A workaround for this is to provide a cmdlet that stores the content in a temporary file. A working example is |
|
Great discussion! Thank you all for the feedback. I'd like to share my plans about this work:
function foo
{
param([byte[]]$rawBytes)
}they may archive it with a temp file or some other technique as @GeeLaw pointed out.
We can revisit the last two parts later, but I'd like to set expectations about scope of this issue. |
|
@vors However the current “>” is identical to |
|
Re-assigned to @JamesWTruher, who will work on this in 7.3 development cycle. |
|
I am interested to know how many people who want the "as-is" bytes are also in the camp of people who are using LF instead of CR LF on their Windows PowerShell scripts... I've proposed a mode that guides behavior based on detection of LF vs. CR LF of the script containing the pipe/redirect: Option for LF vs CR LF Piping To Match Line Endings of Running Script #16511 It may be (?) that someone's feelings about the importance of "as-is" redirection vs CR LF is effectively captured by their git autocrlf setting. So this would piggyback on that. |
|
Perhaps a useful implementation would recognise the historical significance of a
I believe that the preceding could go a long way toward resolving the apparent discontinuity between (legacy) program simple byte oriented CLI I/O and the more powerful but more complicated object oriented PS pipeline. While some potentially breaking changes are involved, I suspect these would mostly affect strategies (kludges?) used to work around the incompatibility issues addressed here. Further, the changes proposed allow original (incompatible) behaviour to be maintained at the PS script level. For native output, no change will occur unless the new |
|
One way to avoid any magic would be that PowerShell inspects a list of exceptions that the user can configure themselves. It could be as simple as a JSON file stored at a specific location in your user profile: {
"exceptions": [
{
"path": "C:\\Python39\\python.exe",
"stdin": "native",
"stdout": "native",
"stderr": "native"
},
]
}Obviously, the exact format and location of the configuration isn't so relevant, but this would make it an easy to configure opt-in feature that does not disrupt the way PowerShell works by default. |
General proposal is in #13428 |
|
Any updates? Seems that without this we cannot use gzip to compress data stream: cat -AsByteStream a.js | gzip > a.gzThe data stream will be corrupted by the This command works on every shell except PowerShell. |
|
@JamesWTruher is this still on your radar? |
|
Can we expect this being committed in 7.3? Whenever I want to write bytes to native executables via pipeline, I have to launch a cmd or bash shell to achieve this, which makes PowerShell really hard to use, and, useless in the scenario where binary data processing against native executables is usual in a script. |
|
This has annoyed me for a long time. |
|
lewis-yeung, it can be quite the pain. The workaround of https://github.com/GeeLaw/PowerShellThingies/tree/master/modules/Use-RawPipeline requires rewriting your commands but can deliver performance for many situations I have found.
|

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Currently PowerShell parses STDOUT as string when piping from an EXE, while in some cases it should be preserved as a byte stream, like this scenario:
or
Affected patterns include:
native | native,native > fileand (maybe)cat file | native.The text was updated successfully, but these errors were encountered: