You will need this to work by expansion if you want to use it directly for a counter, so cannot use \write
. Instead, it's possible to exploit the piped input ability of modern engines. Using a working example with echo
\documentclass{article}
\makeatletter
\newcommand\getinput{\@@input|"echo 1"}
\makeatother
\begin{document}
\newcounter{mycounter}
My Input: \getinput
\addtocounter{mycounter}{\getinput}
My Sum: \themycounter
\end{document}
Here, we need the 'raw' behaviour of the \input
primitive, hence needing to use it's LaTeX name, \@@input
.
If you are happy with a two-step process, first saving the information then using it, you might use the more robust expl3
wrapper around the same idea.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand \saveinput { m m }
{ \sys_get_shell:nnN {#1} { } #2 }
\ExplSyntaxOff
\begin{document}
\newcounter{mycounter}
\saveinput{echo 1}\savedinput
My Input: \savedinput
\addtocounter{mycounter}{\savedinput}
My Sum: \themycounter
\end{document}
\newcommand\getinput[2]{\input{|do-some-things}}
so the output is piped straight to tex with no intermediate file (although you'd still have to make it a number)\getinput
in the counter setting? Or can we use a route where you call the input and save the result in a macro?