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

Re: less with subprocess

On 2021-09-29 07:14:23 -0700, Bart Schaefer wrote:
> On Wed, Sep 29, 2021 at 6:02 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> >
> > cventin% LF () { () { cat >$1 &! less $1 ; kill $! } =(:) }
> > cventin% echo | LF
> > (anon):kill: kill 27684 failed: no such process
> Yeah, if you use it with a process that produces very little output,
> the kill will fail.  But there's no point in using it in that case.

You don't always know in advance whether there will be little output.
And even with a lot of output, "kill" fails. Basically, the "cat" will
terminate as soon as the command terminates (there is no blocking due
to buffering like with a pipe).

There's another major issue: since there is no blocking, this can take
much disk space. Thus such a function must not be used in a case one
may be interested only in the beginning of the output.

> Redirect stderr of kill if this bothers you.

This won't solve the issue that "kill" may kill an arbitrary process.

I'd say that my patch on "less" provides a better solution.

Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

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