Conditionals – How to Read Numbers from a File with Filesystem Access

conditionalsfilesystem-access

I have a file called _runs.ini. Depending on its content, the document is compiled differently. I tried to read the content and executed a \ifthenelse-command without success.

Here's my MWE:

\documentclass{book}
\usepackage{ifthen}

\newcommand\getrun{%
    \newread\tmp
    \openin\tmp=_runs.ini
    \read\tmp to \pruns
    \def\ppruns{\numexpr \pruns\relax}
    \closein\tmp
}

\newcommand\startrun{%
  \ifthenelse{\equal{\ppruns}{0}}
        {true}{false}
}

\begin{document}

\getrun
\startrun

\end{document}

The content of _runs.ini is 0 but obvisously the \equal-command does not recognize it as 0.

What am I doing wrong?

Best Answer

And an answer with the original \ifthenelse

\documentclass{book}
\usepackage{ifthen}

\newcommand\getrun{%
    \newread\tmp
    \openin\tmp=_runs.ini
    \read\tmp to \pruns
    \def\ppruns{\numexpr \pruns\relax}
    \closein\tmp
}

\newcommand\startrun{%
  \ifthenelse{\equal{\pruns}{0 }}%<-- space!
        {true}{false}
}

\newcommand\startrunb{%
  \ifthenelse{\ppruns=0}
        {true}{false}
}

\begin{document}

\getrun
\startrun

\startrunb
\end{document}