Filecontents and newenvironment issue
Probably it's not the right way to use filecontents*
, as egreg says in his comment.
Anyway, changing your MWE to
\documentclass[]{article}
\usepackage{listings}
\usepackage{filecontents}
\newenvironment{MyNewEnvironment}[1]{%
\def\temp{#1}%
\csname filecontents*\endcsname{\temp}%
}%
{\csname endfilecontents*\endcsname%
\lstinputlisting{\temp}%
}%
\begin{document}
\begin{MyNewEnvironment}{foo.txt}
one
two
three
four
five
\end{MyNewEnvironment}
\end{document}
works fine for me.
I suggest using fancyvrb
and xparse
, that allows also to pass options to \lstinputlisting
:
\documentclass{article}
\usepackage{fancyvrb,xparse,listings}
\NewDocumentEnvironment{MyNewEnvironment}{O{}m}
{\VerbatimOut{#2}}
{\endVerbatimOut\lstinputlisting[#1]{#2}}
\begin{document}
\begin{MyNewEnvironment}[columns=fullflexible]{foo.txt}
one
two
three
four
five
\end{MyNewEnvironment}
\end{document}