\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#202: Add 2\tiprangle{}@1 Special Case to [open] and [exec]}
\date{May 19, 2004}
\author{Jeff Hobbs}
\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 \#202}&\textbf{Add 2\tiprangle{}@1 Special Case to [open] and [exec]}\\\hline
Author&

Jeff Hobbs \tipmail{jeffh}{activestate.com}
\\
Created&Wednesday, \(\text{19}^{\text{th}}\) May 2004\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Keywords&Tcl, redirection\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes adding a new redirection case '2\tiprangle{}@1' that redirects the error channel to the output channel in \textbf{open} and \textbf{exec}. This would only be valid at the end of a pipeline.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

Tcl is currently limited on how \textit{stderr} can be managed from a command opened with \textbf{open \tipbar{}} or \textbf{exec}. This TIP adds the ability to simply combine the \textit{stderr} stream with the \textit{stdout} stream by adding a new output redirection case, \textbf{2\tiprangle{}@1} (i.e. as in Bourne shell syntax), that is only ever valid as the last redirection item in a pipeline. This will enable simple capturing of \textit{stderr} as well as \textit{stdout} across platforms.

The behavior is similar to \textbf{2\tiprangle{}@stdout}, but that does not work across platforms. The difference is that directs to a real \textit{stdout} file channel (which is not available in Windows wish for example), whereas \textbf{2\tiprangle{}@1} would redirect to the output result for \textbf{exec}/\textbf{open}.

The intention is to handle the common case of wanting to capture \textit{stderr} as well as \textit{stdout} output from a single command. This operator is only valid as the last redirection operator. To redirect \textit{stderr} of previous commands along with their \textit{stdout}, use the preexisting \textbf{\tipbar{}\&} pipe operator.

This is backwards compatible as \textbf{2\tiprangle{}@1} currently raises an error that ``1'' is not a valid file id (Tcl does not create such file ids).

\subsection{Examples}
\begingroup\small\begin{verbatim}
 set fid [open "|$cmd 2>@1"]
 set result [exec $cmd 2>@1]
\end{verbatim}
\endgroup

\section{Reference Implementation}

See SF Tcl Patch 957132 [\url{http://sf.net/tracker/?func=detail&aid=957132&group_id=10894&atid=310894}] for details.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
