<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sun May 19 15:03:38 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='267'>
<header><title>Allow &apos;exec&apos; to Ignore Stderr</title><author address="mailto:nathanb@actarg.com">Nathan Bell</author><status type='project' state='final' tclversion="8.5" vote='after'>$Revision: 1.4 $</status><history></history><created day='25' month='apr' year='2006' /></header>
<abstract>Currently the <emph style="bold">exec</emph> 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).</abstract>
<body><section title="Rationale">
<para>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 (<emph style="italic">i.e.</emph>, /dev/null). If the program&apos;s output is being used elsewhere (<emph style="italic">i.e.</emph>, 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.</para>
<para>Since standard error can be safely ignored in such circumstances, <emph style="bold">exec</emph> is wrong to report such output as an error. Allowing <emph style="bold">exec</emph> 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.</para>
</section>
<section title="Consequences">
<para>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 <emph style="bold">exec</emph> 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 <emph style="bold">exec</emph> to deal with this as appropriate.</para>
</section>
<section title="Proposed Changes">
<para>As <emph style="bold">exec</emph> already contains the ability to accept options, adding an option to ignore stderr is the most backward compatible fix.</para>
<para>An option <emph style="bold">-ignorestderr</emph> would fit with the existing <emph style="bold">-keepnewline</emph> and proposed <emph style="bold">-binary</emph> (see <tipref type="text" tip="259"/>).</para>
</section>
<section title="Implementation">
<para>A patch exists in the SourceForge feature request section (Request ID 1476191 [<url ref="http://sf.net/tracker/?func=detail&amp;aid=1476191&amp;group_id=10894&amp;atid=360894"/>]).</para>
<para>This patch applies to generic/tclIOCmd.c. If the <emph style="bold">-ignorestderr</emph> option is given, <emph style="italic">Tcl_OpenCommandChannel</emph>() is not passed the TCL_STDERR flag. This is the most straightforward method as it allows the existing functionality of <emph style="italic">Tcl_OpenCommandChannel</emph>() to be exposed to <emph style="bold">exec</emph> command.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
