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.
3 Answers
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.
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`.
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.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically