\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#267: Allow 'exec' to Ignore Stderr}
\date{April 25, 2006}
\author{Nathan Bell}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#267}&\textbf{Allow 'exec' to Ignore Stderr}\\\hline
Author&

Nathan Bell \tipmail{nathanb}{actarg.com}
\\
Created&Tuesday, \(\text{25}^{\text{th}}\) April 2006\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

Currently the \textbf{exec} command will always fail if the process writes to standard error. Since various applications use stderr for debug output it would be useful to retain this output without having to resort to redirecting stderr to stdout (which can cause interleaving).
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Various applications use stderr not just to report errors, but also warnings and debugging information. Right now, the only way to make such a program behave sensibly is to redirect stderr to stdout, or to a null device (\textit{i.e.}, /dev/null). If the program's output is being used elsewhere (\textit{i.e.}, to generate a document), stderr is the only means of reporting debugging or progress information to the user. This information is lost if a redirect is used.

Since standard error can be safely ignored in such circumstances, \textbf{exec} is wrong to report such output as an error. Allowing \textbf{exec} to ignore stderr in those situations would be both beneficial and more correct. It should not be enabled by default though, as other applications write to stderr solely to indicate that an error occurred, and do not generate a non-zero exit code.

\section{Consequences}

Many applications use stderr for debugging and error reporting. When a program fails, it will often return an error code and report the problem to stderr. If \textbf{exec} is ignoring stderr such a error report will also be ignored, leaving the tcl script with just the knowledge that some error occurred. If the script is being run in a terminal or on the console, the stderr will be reported directly to the user, but the script will have no way of getting the information. It is up to the user of \textbf{exec} to deal with this as appropriate.

\section{Proposed Changes}

As \textbf{exec} already contains the ability to accept options, adding an option to ignore stderr is the most backward compatible fix.

An option \textbf{-ignorestderr} would fit with the existing \textbf{-keepnewline} and proposed \textbf{-binary} (see \cite{tip259}).

\section{Implementation}

A patch exists in the SourceForge feature request section (Request ID 1476191 [\url{http://sf.net/tracker/?func=detail&aid=1476191&group_id=10894&atid=360894}]).

This patch applies to generic/tclIOCmd.c. If the \textbf{-ignorestderr} option is given, \textit{Tcl\_OpenCommandChannel}() is not passed the TCL\_STDERR flag. This is the most straightforward method as it allows the existing functionality of \textit{Tcl\_OpenCommandChannel}() to be exposed to \textbf{exec} command.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#259]{tip259}
Andreas Leitgeb,
\emph{Making 'exec' Optionally Binary Safe},
on-line at \url{http://purl.org/tcl/tip/259.html}
\end{thebibliography}
\end{document}
