Only in ../tcl8.5.9/generic: tags
diff -ru tcl8.5.9/generic/tclIO.c ../tcl8.5.9/generic/tclIO.c
--- tcl8.5.9/generic/tclIO.c	2010-03-20 10:53:07.000000000 -0700
+++ ../tcl8.5.9/generic/tclIO.c	2011-05-25 10:23:48.000000000 -0700
@@ -394,6 +394,7 @@
  *----------------------------------------------------------------------
  */
 
+void invalidate_iocmd_tsd();
 void
 Tcl_SetStdChannel(
     Tcl_Channel channel,
@@ -408,6 +409,7 @@
     case TCL_STDOUT:
 	tsdPtr->stdoutInitialized = 1;
 	tsdPtr->stdoutChannel = channel;
+        invalidate_iocmd_tsd();
 	break;
     case TCL_STDERR:
 	tsdPtr->stderrInitialized = 1;
diff -ru tcl8.5.9/generic/tclIOCmd.c ../tcl8.5.9/generic/tclIOCmd.c
--- tcl8.5.9/generic/tclIOCmd.c	2010-02-11 07:25:25.000000000 -0800
+++ ../tcl8.5.9/generic/tclIOCmd.c	2011-05-25 10:23:13.000000000 -0700
@@ -84,6 +84,12 @@
     }
     tsdPtr->initialized = 0;
 }
+
+void invalidate_iocmd_tsd()
+{
+  FinalizeIOCmdTSD(0);
+}
+
 
 /*
  *----------------------------------------------------------------------
