Platform independent approach using
texosquery (requires Java):
It needs the shell escape. If the file is called
pdflatex -shell-escape test
With MikTeX, you also need the piped shell escape enabled (
There are three variants of
texosquery-jre5: requires at least Java 5, but doesn't have the full set of features and is less secure;
texosquery (default): requires at least Java 7, has almost the full set of features, but certain file operations have restrictions;
texosquery-jre8: requires at least Java 8, has the full set of features, but certain file operations have restrictions, and is now on TeX Live's list of trusted applications.
So if you have Java 8 and
texosquery-jre8 is on the restricted list (which it is for TL2017) then you can use the restricted shell escape.
To switch from the default
texosquery-jre8, you need to edit the
texosquery.cfg file. The simplest method is to copy the installed
texosquery.cfg to your local or home TEXMF tree and edit it from there. That way it won't be overwritten when the distribution is updated.
\TeXOSInvokerName to the required application:
Uncomment the following line to allow the application to be run in restricted mode:
(Only do this if the application is actually on the restricted list.) Now you can just do (with TeX Live):
or with MikTeX:
pdflatex --enable-pipes test
Also works with plain eTeX:
% iterate over comma-separated list stored in \result using your preferred method