\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{kondou}[2019/12/13 Kondou]

\newcommand{\kondou}[3]{
  \newread\myinput
  % We use '\jobname.temp' to create a uniquely-named temporary file
  \immediate\write18{kondou -q -o #1 #3 | tr -d '[]&' > '\jobname.temp'}
  \openin\myinput=\jobname.temp
  % The group localizes the change to \endlinechar
  \bgroup
    \endlinechar=-1
    \read\myinput to \localline
    % Since everything in the group is local, we have to explicitly make the
    % assignment global
    \global\let\thechatcode\localline
  \egroup
  \closein\myinput
  % Clean up after ourselves
  \immediate\write18{rm -f -- '\jobname.temp'}

  \begin{figure}[ht]
    \centering
    \includegraphics[width=0.7\textwidth]{#1}
    \caption[]{#2 \\ (\texttt{[\&\thechatcode])}}
  \end{figure}
}
