I want to output some text, verbatim, to $TMPDIR/myFile.txt, then do some other operations with that file.
Note: to allow LaTeX to write to files outside the current folder, you need to:
- Run LaTeX with
--shell-escapeto allow for\input - Add
openout_any=atotexmf.cnfto allow writing to any folder (findable in a terminal viakpsewhich texmf.cnf)
I'm trying to obtain the real file path via \input{|echo $TMPDIR/myFile.txt} as per:
https://stackoverflow.com/questions/3252957/how-to-execute-shell-script-from-latex
with complete minimal repro:
\documentclass[11pt]{article}
\usepackage{fancyvrb}
\begin{document}
\newcommand{\myFile}{\immediate\input{|echo $TMPDIR/myFile.txt}}
\begin{VerbatimOut}{\myFile}
my file contents here <> {} () $ "" ''.
\end{VerbatimOut}
% ... do something on disk with \myFile
\end{document}
However, this generates an error Bad space factor (0). on the \end{VerbatimOut} line.
Possibly related:
! Bad space factor (0)
but that answer (\leavevmode) sounds specific to seriate.
Why is this error generated, and is there a way to accomplish the above goal?

\immediatefrom\immediate\input– David Carlisle Dec 11 '22 at 19:21\inputis not expandable so\myFiledoes not expand to a file name so\begin{VerbatimOut}{\myFile}can not work – David Carlisle Dec 11 '22 at 19:24\input, I found various pages describing its functionality, but none mentioned its expandability.When something isn't expandable and is misused, it tends to cause poor errors.
Should people just assume that everything isn't expandable, and only use
– David Fink Dec 12 '22 at 11:46expl3definitions when expandable functions are required?\inputbasically everywhere with any content." and "You can nest\inputmacros.", which is pretty confusing, since it isn't expandable. https://tex.stackexchange.com/questions/246/when-should-i-use-input-vs-include – David Fink Dec 12 '22 at 11:52The LaTeX version of \input only does some sanity checks and then...those checks... – David Carlisle Dec 12 '22 at 11:55