Markus
10/16/2004 6:09:00 AM
What sort of errors? In other words, are they appropriate to the
place where they occur, assuming that garbage got through from the dead
pipe, or do they look like they are the uncaught pipe errors magically
reincarnated in a new place?
Looking at your code, I suspect that "line" might be some unhappy
value if @file is questionable coming out of popen. Are you getting
"eek"ed at?
-- Markus
On Fri, 2004-10-15 at 18:49, David G. Andersen wrote:
> This is likely my brain missing something, but I'm having a hard
> time figuring out the source of this error. I have code that
> does:
>
> class foo
>
> def get_next_line
> if the file isn't open
> @file = popen("zcat <file>")
> end
> begin
> line = @file.readline
> return line
> rescue => err
> print "eek: #{err}\n"
> end
> end
>
> def process
> line = get_next_line
> process_line(line)
> end
>
> class bar < foo
> def process_line(line)
> .. do something with the line ..
> .. write to a file ..
> end
> end
>
> The problem is that the popen exits, typically with a
> non-zero exitcode (garbage at the end of the gzipped file).
> The next time the program does something in the
> process_line function - typically writing to a file,
> or reading/writing to/from the database - _that_
> operation generates an error.
>
> I assume I'm doing something wrong with respect to
> trapping the errors from the popen, but I'm baffled
> about exactly what I should do.
>
> Clues _very_ appreciated; I've been bashing my head
> on this for a while. Stuffing in lots and lots of
> begin / end checks around the operations in process_line
> typically does the trick, but it's very.. uhh, inelegant.
>
> Thanks!
>
> -dave