I have following document:
\documentclass[parskip=half-]{scrreprt}
\usepackage{ragged2e}
\usepackage{makecell,xltabular}
\usepackage[dvipsnames,x11names,table]{xcolor}
\begin{document}
\subsection{Test table}
\begin{xltabular}{\textwidth}{|>{\ttfamily\RaggedRight\arraybackslash}p{6.5cm}|>{\centering\arraybackslash}p{0.6cm}|m{1.8cm}|X|}
\caption{Table caption}
\label{tab:test-table}\
\hline
\rowcolor{gray}
\thead{\textnormal{Col1}} & \thead{Col2} & \thead{Col3} & \thead{Col4} \ \hline
\endfirsthead
%
\multicolumn{4}{c}%
{{\bfseries Table \thetable\ continued from previous page}} \
\hline
\rowcolor{gray}
\thead{\textnormal{Col1}} & \thead{Col2} & \thead{Col3} & \thead{Col4} \ \hline
\endhead
%
\multicolumn{4}{|c|}{\cellcolor{lightgray}\textbf{Table section}} \ \hline
1 & 2 & 3 & 4 \ \hline
\input{|"./test.py"}
\end{xltabular}
\end{document}
I'm using an \input with pipe:
\input{|"./test.py"}
If the content of the test.py is:
#!/usr/bin/env python3
print(r'\multicolumn{4}{|c|}{\cellcolor{lightgray}\textbf{Table section 2}} \ \hline')
print(r'11 & 22 & 33 & 44 \ \hline')
I get an error:
! Misplaced \omit.
\multispan ->\omit
\@multispan
l.1 ...llcolor{lightgray}\textbf{Table section 2}}
\\ \hline
! ==> Fatal error occurred, no output PDF file produced!
If I swap two last lines in the python script, I don't get an error but the table has two extra vertical lines.
#!/usr/bin/env python3
print(r'11 & 22 & 33 & 44 \ \hline')
print(r'\multicolumn{4}{|c|}{\cellcolor{lightgray}\textbf{Table section 2}} \ \hline')
I generate pdf with: latexmk -shell-escape -enable-pipes -pdf -halt-on-error test.tex
What I'm doing wrong?

\inputis not expandable and has... issues... when used in tabular-like environments. Related question expansion - Completely expandable loop macro that also works in tabular - TeX - LaTeX Stack Exchange – user202729 Jul 19 '22 at 03:05\\ \hlineat the start of the input not the end (and adjust the outer document accordingly) – David Carlisle Jul 19 '22 at 06:38