# How to read *all* input from stdin?

The answers given to this similar question won't do, because those solutions read only one line from stdin.

I want to read all available lines, pretty much in the way that standard Unix programs like cat, grep, wc, etc. do.

EDIT: I'd prefer a "pure-Mathematica" solution, if possible.

• You don't have to accept yet. I'll be surprised if there's a better solution, but let's wait a bit anyway. People are more likely to look at a question if it isn't marked as answered. – Szabolcs Dec 15 '16 at 16:25
• @Szabolcs: done – kjo Dec 15 '16 at 16:26

I am not aware of any pure Mathematica solution. The usual way is to read from the stream

stream = OpenRead["!cat"]


You can do this directly with any read functions, such as Import, Read, ReadString, ReadList, etc. For example,

Import["!cat", "String"]


I spent a considerable amount of time searching for a simpler solution, and while I cannot rule out that it exists, I wasn't able to find it. You can also read from StartProcess["cat"] (it's readable as a stream), but that's basically the same thing.

These solutions do read all lines on OS X. wolframscript (new in 11) can read from stdin without extra help, but it's buggy: it only reads the data available in the buffer, and then it exists. It doesn't wait for new data like cat does.