Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: cb1cd61df499fa8218cc8ef33a957122408cea3d
Ticket: 217779ffffffffffffffffffffffffffffffffff
Semantics of redirect: 2>@stdout may not be correct
User & Date: nobody on 2000-10-26 00:43:32
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 682 Bug
    Version: 8.0.3
    SubmitDate: '1998-09-24'
    LastModified: '2000-04-26'
    Severity: LOW
    Status: Closed
    Submitter: welch
    ChangedBy: hobbs
    RelatedBugIDs: 582 1470
    OS: All Windows
    FixedDate: '2000-10-25'
    FixedInVersion: NA
    ClosedDate: '2000-04-26'
    
    
    This is a bug on the *unix* side for tclsh (it is still present in 8.0.3).
    
    When you do
    
    set x [exec gcc -v 2>@ stdout]
    
    you get the child's stderr into $x. (gcc -v writes to its stderr)
    
    This *is* a bug, because here "2>@ stdout" behaves exactly like "2>&1"
    in  Bourne shell;  this  is not the proper semantics for  Tcl, because
    "@stdout" should be interpreted as "tclsh's stdout" and *not* what the
    "1" file descriptor happens  to be  at that  time (within  the child),
    i.e. exec's output pipe.
    
    Another  way of  looking  at it: this  semantics  should make  the ">@
    stdout" construct equivalent to nothing. But it is not:
    
    set x [exec date >@ stdout]
    
    properly  outputs the  date  to tclsh's stdout,  and stores  the empty
    string in x.  So there seems to be a special case around 2>@stdout.
    
    Nasty, eh ?
    
     Please note that Ian Taylor's "patch" (in  your Patches page) on this
    subject,  duplicates this  *wrong*  behavior on Windows,  because  Ian
    finds it handy for his particular case... So I'm also saying that this
    patch   should   be   rejected.    (But    I   got   no   reply   from
    [email protected]).
    
     Ian and I have come to the agreement that a *feature* should be added
    instead: allowing the Bourne shell "N>&P" notation (N and  P in [0-9])
    inside  exec and open. This syntax extension  would support the wanted
    low-level descriptor semantics, hence he could write:
    
    set x [exec gcc -v 2>&1]
    
    while
    
    set x [exec gcc -v 2>@ stdout]
    
    would correctly output  the gcc  version to tclsh's stdout,  and store
    the empty string into x.
    
    
    Here is a more consise description of the problem:
    
    Currently on unix:
    % puts "{[exec echo plop >@ stdout]}"
    {}
    
    #  This  is  correct:  ">@ stdout" means "redirect the
    # child's descriptor 1 to Tcl's stdout".
    
    However:
    % puts "{[exec sh -c {echo plop >&2} 2>@ stdout]}"
    {plop}
    
    #  This is wrong: here "2>@  stdout" is interpreted as
    # "redirect the child's descriptor 2 to its descriptor
    # 1 (which is the pipe gathering exec's result)"
    
    # In other  terms "2>@ stdout" behaves  as  "2>&1"  in
    # Bourne shell;  this  can be  separately useful,  but
    # it's not hmogeneous with the first case.
    
    # Note also that  this only affects  "2>@ stdout". All
    # other related  cases, like "2>@  other_stream",  ">@
    # stdout",  "<@  stdin",  and even  ">&@ stderr", work
    # correctly.
    
    # So  all  this amounts to a strange and buggy special
    # case  for  2>@ stdout.  Ironically,  this is exactly
    # this strange and  buggy special case that Ian Taylor
    # wanted to 'port' to the Windoze world...
     
    -- 04/26/2000 hobbs
    
  4. foundin changed to: "obsolete: 8.0.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "60. NRE and coroutines"
  10. title changed to:
    Semantics of redirect: 2>@stdout may not be correct
    
  11. type changed to: "Bug"