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

Re: Capturing STDOUT without subshells or file I/O



On Mon, Sep 17, 2018 at 10:46 PM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Ben Klein wrote on Mon, 17 Sep 2018 16:13 -0400:
>> So I guess the question is up again, how should I capture the `printf`
>> output without the `-v` option, no subshells, and no file I/O? Is there
>> a different method for ZSH v5.1?
>>
>> I would like to do `printf '%.2f' "3.4" | read var` but it appears that
>> the command before the pipe causes a subshell to be opened.
>>
>
> If you could call pipe(2), you'd be able to do
> .
>     printf foo >&$w
>     read bar <&$r
> .
> without forking (where $r,$w were returned by pipe(2)).  However, I
> don't see any suitable callsite in the 5.6 codebase.  (Don't have 5.1
> handy, sorry.)
>
> Maybe we should expose pipe(2) in zsh/system?

That's just a deadlock-by-design.

-- 
Mikael Magnusson



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