Why Does Piping Raw Image Bytes Through a PowerShell Function Fail?

August 7, 2026 3 answers
Asked by MellowPine47
Why does piping ImageMagick's raw PNG output directly into chafa work, while wrapping chafa in a PowerShell function causes it to fail? The direct command works in PowerShell 7.6: `magick _.png -negate png:- | chafa --size=70x -f sixel -`. However, this function-based version does not: `function img { chafa.exe --size=70x -f sixel @args }` followed by `magick _.png -negate png:- | img -`. The goal is to preserve the raw byte stream and have chafa read it from standard input.

Answers

CrispHarbor8
PowerShell can pass native stdout as raw bytes when one native executable is directly piped to another. In the second command, the pipeline target is a PowerShell function, so PowerShell handles the data through its object pipeline instead of connecting the native programs' standard streams directly. The bytes are no longer preserved as a raw stdin stream for chafa.
Reply to this answer
LunarCactus29
The function also doesn't receive or forward pipeline input. `img -` doesn't automatically mean โ€œread stdinโ€ here; the dash is just an argument, and PowerShell functions don't interpret it like a native program does. You would need a pipeline-bound parameter and code that explicitly writes the received data to the child process's standard input using .NET APIs such as `System.Diagnostics.Process`.
Reply to this answer
QuietMaple6
The direct form works because chafa itself understands `-` and has the native-program logic needed to read standard input. Your wrapper currently just launches `chafa.exe --size=70x -f sixel` and ignores anything arriving at the function. For this raw-byte case, the simplest solution is to keep the native commands directly connected rather than putting a PowerShell function between them.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions