Reading `STDIN` on Windows in MSYS2

Setup

  1. Symfony Console application.
  2. Packed into a Phar with Box.
  3. Distributed as an executable for Win, Linux, and MacOS with PHPMicro.

Execution

  1. MSYS2 on Win11.
  2. make import calls app import < "$filename" in a loop for an ordered list of inputs.
    1. Alternatively, cat "$filename" | app import.

Problem

Cannot read from STDIN: ftell(STDIN) returns false. There’s no data in the stream. Similar story with fopen('php://stdin', 'r').

winpty

Without winpty, I see my debug output, and can e.g. inspect the stream (that’s how I know it’s empty).

With winpty, none of that happens, and instead I get:

$ winpty un1q import:generic < datafile.csv
stdin is not a tty

Remarks

Works fine on Linux. I don’t really understand how MSYS2 works, especially with streams and pipes. From what I understood, it should transform my Bash syntax into something it runs in CMD or PowerShell (none of which I’m very familiar with).