TIP #267: Allow 'exec' to Ignore Stderr

Title:Allow 'exec' to Ignore Stderr
Version:$Revision: 1.4 $
Author:Nathan Bell <nathanb at actarg dot com>
Created:Tuesday, 25 April 2006


Currently the 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).


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 (i.e., /dev/null). If the program's output is being used elsewhere (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, exec is wrong to report such output as an error. Allowing 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.


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 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 exec to deal with this as appropriate.

Proposed Changes

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

An option -ignorestderr would fit with the existing -keepnewline and proposed -binary (see TIP #259).


A patch exists in the SourceForge feature request section (Request ID 1476191 [1]).

This patch applies to generic/tclIOCmd.c. If the -ignorestderr option is given, Tcl_OpenCommandChannel() is not passed the TCL_STDERR flag. This is the most straightforward method as it allows the existing functionality of Tcl_OpenCommandChannel() to be exposed to exec command.


This document has been placed in the public domain.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows