TIP 267: Allow 'exec' to Ignore Stderr

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:		Nathan Bell <nathanb@actarg.com>
State:		Final
Type:		Project
Tcl-Version:	8.5
Vote:		Done
Created:	25-Apr-2006
Post-History:	

Abstract

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

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 (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.

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 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 [259]).

Implementation

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

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.

Copyright

This document has been placed in the public domain.

History