Hi Larry,

> Groff was barfing with a "too many open files" error, which I worked around 
> by doing "ulimit -n 768" first. I ended up with over 640 HTML files. I'm not 
> sure why all every output file has to be open at once, though.

Sounds like either a bug or a design artifact that'll need fixing in the
long run.

>   awk -v stem="$1" '
>     # ...
>     / ... / {
>        grep = "grep -n \"" lasthdg "\" " stem ".ohc";
>        grep | getline ohc;
>      }
>   ' $2-$i.html >> $$.tmp
> 
> I'm also getting a "too many open files" error thrown in this part of the 
> script. 
> Is there any way I can explicitly close the getline pipe, besides looping 
> until it 
> returns 0 for EOF?

Yes, there's close().  IIRC awk doesn't close a file or pipe even when
you reach EOF so it's up to you to close it yourself.  Further, if the
command is the same as previously, you must close it in order to get a
new command to run:

    $ cat t
    BEGIN {
        "d=`date`; echo 1 $d; echo 2 $d" | getline foo
        "sleep 2" | getline snooze
        "d=`date`; echo 1 $d; echo 2 $d" | getline bar
        print foo "," snooze "," bar
        exit
    }
    $ awk -f t
    1 2006-12-01 12:22:27 +0000 Fri,,2 2006-12-01 12:22:27 +0000 Fri
    $

foo and bar are both read from the one command that's run, hence the
date not changing and the line numbers progressing.  However,

    $ cat u
    BEGIN {
        "d=`date`; echo 1 $d; echo 2 $d" | getline foo
        close("d=`date`; echo 1 $d; echo 2 $d")
        "sleep 2" | getline snooze
        close("sleep 2")
        "d=`date`; echo 1 $d; echo 2 $d" | getline bar
        close("d=`date`; echo 1 $d; echo 2 $d")
        print foo "," snooze "," bar
        exit
    }
    $ awk -f u
    1 2006-12-01 12:24:43 +0000 Fri,,1 2006-12-01 12:24:45 +0000 Fri
    $

What status close() returns depends on your awk.  And closing a pipe
should wait for the command to finish so if you've a grep that produces
1E6 lines and you just want to read the first then pipe it into `sed 1q'
before reading it into awk so the grep gets a SIGPIPE on writing to the
finished sed, curtailing its largess.

Cheers,


Ralph.




_______________________________________________
Groff mailing list
Groff@gnu.org
http://lists.gnu.org/mailman/listinfo/groff

Reply via email to