Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 2b396df997eb5100b753358a581102a9640463fe5556aadce9b66f99d2342239
Ticket: 204ac7df2468599bf8c82fa82a147b79a35ef1d2
Incorrect handling of redirection in process piping
User & Date: euller on 2019-04-30 18:37:12
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    Tcl behaves erratically when stdout and stderr are redirected in intermediate pipe stages of an exec call.
    
    Suppose a program called "print_stderr" that prints "COUT" to stdout and "CERR" to stderr. The following works properly:
     % echo "BLA" 1>ble | ./print_stderr
     STDOUT
     STDERR
     % cat ble
     BLA
    
    But when we remove the "1" from the redirection, this is what we get:
     % echo "BLA" >ble | ./print_stderr
     %cat ble
     STDOUT
     STDERR
    
    The problem also happens when redirecting stderr:
     % echo "BLA" 2>ble | ./print_stderr
     STDOUT
     % cat ble
     STDERR
    
    Notice how the redirection happens for the whole command and not only for echo.
    
    There's a specific problem with ">file" since it redirects both stderr and stdout when it should only redirect stdout (and only for echo in the example!), according to documentation:
        > fileName
          Standard output from the last command is redirected to the file named fileName, overwriting its previous contents.
    
    The behaviour for stderr is unexpected but maybe understandable since the documentation states:
        2> fileName
          Standard error from all commands in the pipeline is redirected to the file named fileName, overwriting its previous contents.
    Still, this should only be valid in the last stage of the pipeline, in my opinion.
    Consider, for example, the following scenario:
      % echo "BLA" >ble | ./print_stderr >bli
      % cat ble
      % cat bli
      STDOUT
      STDERR
    
    All these behaviours are very different from their shell counterparts, meaning we don't get the same expressiveness we'd get from actually running a shell command.
    
  5. foundin changed to: "8.6.9"
  6. is_private changed to: "0"
  7. login: "euller"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "c73040ce352899ef6ad98381bd8f919cd232c428"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "euller"
  14. subsystem changed to: "45. Parsing and Eval"
  15. title changed to:
    Incorrect handling of redirection in process piping
    
  16. type changed to: "Bug"