Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Capture stdout, stdin, and exit status in different variables without using temporary files



On Fri, Aug 16, 2019 at 3:03 PM TJ Luoma <luomat@xxxxxxxxx> wrote:

> I have used this, which I am sure someone on the zsh probably gave me:
>
> (){ STDOUT=$( your-command-here 2> $1) STDERR=$(<$1);} =(:)
>

The OP is asking for a solution that doesn't use temporary files, so this
doesn't fit.

FWIW, this recipe is what I use when I need to capture stdout and stderr.
It works great. On modern Linux distros /tmp is usually on an in-memory
filesystem, so no disk IO happens when you are using temporary files. Even
when you have to hit disk, modern SSDs are very fast, with read/write
speeds over 3GB per second. Having sequential SSD reads/writes as a
bottleneck is a tough task even for C code and virtually impossible for zsh
scripts.

Roman.


Messages sorted by: Reverse Date, Date, Thread, Author