# how to execute external commands from (Xe)(La)TeX?

i'm trying to capture output from an external command in a XeLaTeX document. as per http://tex.stackexchange.com/a/20566/28067 and http://stackoverflow.com/a/8929976/256361, i'm specifically doing

\documentclass[a5paper]{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}

\begin{document}

A A A

\immediate\input{|"node -v"}

B B B

\end{document}


i'm running TeX with xelatex --enable-write18 --enable-pipes write18.tex to enable features normally blocked (because security).

however, this does not appear to work. i've tried the \input command with and without the braces, and with and without \immediate, but as long as that line is in the source, XeLaTeX concludes output with

(./write18.aux
)


rather than

(./write18.aux) )
Output written on write18.pdf (1 page).
Transcript written on write18.log.


(ie there is an additional newline, and output just stops dead without the remaining lines). observe that on my system, the output of node -v is the completely un-dangerous string v0.11.7. i understand that in order to capture more arbitrary output i'd have to fiddle with catcodes, but that's food for another question.

so what am i doing wrong here?

Update @egreg you might be right! i tried

\immediate\write18{node -v > /tmp/temp.dat}
\input{/tmp/temp.dat}


and that did work. funny though it would appear you told readers in a comment to http://tex.stackexchange.com/a/20566/28067 that "in TeX Live 2013 the syntax \input|"command" is supported also by XeTeX"–were you in error here?

btw the fact that (in TeXLive) using non-supported command line options do not seem to trigger error messages does not exactly help make testing easier. also funny that http://docs.miktex.org/manual/xetex.html has all the long options prefixed with two dashes where xelatex --help gives them with a single dash (and fails to even mention that many more options are available).

-
Unfortunately, the pipe doesn't seem to work on XeTeX. –  egreg Jan 8 '14 at 15:20
You are using xelatex. Latex redefines \input and so - as mentioned in the first question you are linking too - you must use \makeatletter\@@input|"...". –  Ulrike Fischer Jan 8 '14 at 15:54
@UlrikeFischer i'm trying to get that working but seemingly can't. if you're confident, mind to share a MWE with the rest of us? –  flow Jan 8 '14 at 16:24

I used this

\documentclass{article}

\begin{document}

\makeatletter
\@@input|"dir"

\end{document}


which gave me some errors as the output of dir also contains a path with a backslash but beside this did what was expected: I got 12 pages of more or less sensible output (my test folder is large ;-)). I called xelatex with --enable-pipes --shell-excape. It worked with miktex and TL 2013 on windows. (--enable-pipes is not known in texlive but did no harm).

-
see, that's the difference—i'm working on OSX, not on windows. doing the exact code you gave (with ls substituting dir) i get the behavior described in my question. i'm not surprised that miktex behaves differently, but that TeXLive is si different on different OSes is new to me. –  flow Jan 8 '14 at 17:27
Gotta love the test folder. :) Currently mine has 384 files (per ls -1 | wc -l) :) –  Paulo Cereda Jan 9 '14 at 0:08