Viewing 1 post (of 1 total)
  • Author
  • #21382

    Yang Yang

    Hi all, hello Yutaka, long time no see! Today I bump into a problem that the External Tool function fails to serve document content to the external tool. I’ve tested it with 32-bit v10.1.1 and 16.2.1, both on Windows 7 64 Simplified Chinese Edition. Here is the detail.

    For several years I’ve configured an external tool to run Python snippets on the fly. The external tool is actually a Go binary to call Python with document content as stdin, but here I’ll use an equivalent Python script for clarity:

    import subprocess
    import sys
    def main():
        PYTHON_CMD = r'D:\Tools\Python\python.exe -'
        ENCODING = 'utf-8'
        content =  # read binary data; use ioutil.ReadAll() in Go
        # Should not happen: even an empty file has a newline to read.
        if not content:
            print(">>> Empty content! Debugging time. <<<", file=sys.stderr)
        if content[-1] == 0x1a:  # strip possible trailing Ctrl-Z
            content = content[:-1]
        output =,
    if __name__ == '__main__':

    It reads binary data from stdin, feeds it to the Python interpreter, and write the output to stdout. Both stdin and stdout are UTF-8 encoded.

    The External Tool is configured like this:

    External Tool configuration

    This has worked wonderfully for years without any issue (encoding related in particular). But with some documents, the “Should not happen” part does happen: nothing is read at all. A minimal example,, is uploaded here (not pasted because space or encoding varieties may scare this issue away):

    Note that what really matters is the multi-line string in Removing any line from it will make the External Tool work. In contrast, type | python always works well.

    By the way, I’m using Python 3, so an encoding comment line is not strictly required.

    Any suggestion is appreciated. Thanks a lot!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.