Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 314740cccfb07fc1ef0597b041155adb91862f66b0a530cc82a9cecc71322a71
Ticket: 0f1ddc0df7fb734cf1cba12ac7c529d29fefb842
exec fails on encoding errors present in the output of the executed command
User & Date: dkf on 2023-11-27 16:47:26
Changes

  1. icomment:
    The `exec` command is notably very simple-minded in that it uses the system encoding for everything including for the encoding of channels used to communicate with the subprocess, and it always assumes that output is readable text in that encoding. *It very much is known that this isn't always so!* However, "fixing" this tends to make `exec` much harder to use in the simple cases.
    
    The ***workaround*** is to use a pipeline, perhaps like this:
    ```
      set f [open |$cmd rb]
      # Binary output can be any byte sequence; no encoding problems possible
      set output [read $f]
      catch {close $f} err
    ```
    Since you have access to the channel above (unlike inside `exec` which handles all of that internally) you can configure it any way you want to handle the input or output you expect. (It also makes it easier to capture stderr of the pipeline without losing stdout, etc.)
    
    Note that both `exec` and `open |...` are wrappers around the same subsystem.
    
  2. login: "dkf"
  3. mimetype: "text/x-markdown"