Quill Notes: Of Channel Transforms and Stdout

So I have a simple enough case. I want Quill to execute a test suite; and sometimes I want to accumulate the output and sometimes I simply want it to be displayed to the console. This is easy enough. To accumulate the result,

    exec {*}$command 2>@1

and to display it to the console

    exec {*}$command >@ stdout 2>@ stderr

The problem arises when I want to do both: let the command write output to the console as it runs, so as to give immediate feedback to the user, but also capture it for later.

If I were always running on Un*x systems, I could add “tee” to the command line; but I can’t assume that on Windows. If I were using [bgexec] I could run the command in the background, listening to the output, and save it and output it. But I’m not using [bgexec], since it isn’t readily available. I could add “tee” as a subcommand to Quill, and include Quill on the command line; which seems overly complicated and fragile.

So I got clever. I wrote a Tcl channel transform that stashes the written data in a variable and returns it unchanged, and pushed it onto the stdout channel. There were some quirks, but I got it working. And then I tried it with the second [exec] command:

exec {*}$command >@ stdout 2>@ stderr

And of course it didn’t work, because the stdout file handle is getting passed to the subprocess running the tests, and the stacked transform only exists in the calling process. D’oh!

WordPress Themes