in reply to Re: pipe to less crash
in thread pipe to less crash

Okay, thanks. I now added a trap for SIGPIPE and I got an error "can't close: status = -1 at ...". So what do I from there? Also, here is code. Thanks again.

$SIG{PIPE} = 'IGNORE'; open LESS, '|less' or die "unable to start pager"; print LESS $string or die "cant write: $!"; close LESS or die "can't close: status = $?"; system("clear");

Replies are listed 'Best First'.
Re^3: pipe to less crash
by ikegami (Patriarch) on Jul 02, 2011 at 02:31 UTC
    There was an error: You tried to write to a broken pipe.
    if (!print LESS $string) { die "cant write: $!" if !$!{EPIPE}; } close LESS;
Re^3: pipe to less crash
by Corion (Patriarch) on Jul 01, 2011 at 19:04 UTC

    So, if you don't want your program to die, why do you use close or die? There are valid situations when close returns a false value, as you've found out, for example when the receiving end of the pipe has gone away.

      The way my program works is that the user sees a list of files and they can choose one and it will open with less, but then once they exit less, I want them to be brought to the program.

        I'm sorry that I was unclear in my response.

        In your code, you use the following statement:

        close LESS or die "can't close: status = $?";

        ... but you do not seem to want your program to die. So, a solution is to not call die instead:

        close LESS;