202.md at [471ebf376d]

Login

File tip/202.md artifact 4f5279efc9 part of check-in 471ebf376d


# TIP 202: Add 2>@1 Special Case to [open] and [exec]
	Author:		Jeff Hobbs <[email protected]>
	State:		Final
	Type:		Project
	Tcl-Version:	8.5
	Vote:		Done
	Created:	19-May-2004
	Post-History:	
	Keywords:	Tcl, redirection
	Tcl-Ticket:	957132
-----

# Abstract

This TIP proposes adding a new redirection case '2>@1' that redirects
the error channel to the output channel in **open** and **exec**.
This would only be valid at the end of a pipeline.

# Rationale

Tcl is currently limited on how _stderr_ can be managed from a
command opened with **open \|** or **exec**.  This TIP adds the
ability to simply combine the _stderr_ stream with the _stdout_
stream by adding a new output redirection case, **2>@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 _stderr_
as well as _stdout_ across platforms.

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

The intention is to handle the common case of wanting to capture
_stderr_ as well as _stdout_ output from a single command.  This
operator is only valid as the last redirection operator.  To redirect
_stderr_ of previous commands along with their _stdout_, use the
preexisting **\|&** pipe operator.

This is backwards compatible as **2>@1** currently raises an error
that "1" is not a valid file id \(Tcl does not create such file ids\).

## Examples

	 set fid [open "|$cmd 2>@1"]
	 set result [exec $cmd 2>@1]

# Reference Implementation 

See SF Tcl Patch 957132
<http://sf.net/tracker/?func=detail&aid=957132&group_id=10894&atid=310894> 
for details.

# Copyright 

This document has been placed in the public domain.