D
David G. Andersen
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
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