0

In one of the legacy application I am working, we are trying to get extracted zip file name through Open3 utility. This is divided into two commands. First command unzip the compressed file and the second one tries to list and grep filename with specific extension. But recently we started encountering error while reading IO buffer.

# unzip with 7z
Open3.capture3("7z", "x", my_zip.path, "-p#{my_pass}", "-o#{tmp_dir}")

# extract file name with .dbf extension
resp, _threads = Open3.pipeline_r(["7z", "-slt", "l", "-p#{my_pass}", my_zip.path], ["grep", "-oP", "(?<=Path = ).+dbf"]) 

# read IO stream for filename
res_filename = resp.readline.strip

# close stream
# resp.close

at resp.readline.strip we are encoutering EOFError. I tried to using ::gets instead of readline to avoid EOFError but it will lead to empty/nil value.

What am I missing? Is there any way to convert IO stream to String object or something like that?

Observed that this is working fine from console but raising exception when job invoked from sidekiq dashboard

Aparichith
  • 1,452
  • 4
  • 20
  • 40
  • Do the commands work outside of Ruby for the zip files that result in a `EOFError`? – Stefan Nov 04 '22 at 10:50
  • yes they do @Stefan – Aparichith Nov 04 '22 at 10:56
  • This issue wasn't there previously. Started from a week – Aparichith Nov 04 '22 at 10:57
  • Just observed that these commands are working fine from console. But raising error when we enqueue it from sidekiq – Aparichith Nov 04 '22 at 11:31
  • If the same code used to work just fine, the problem's cause is most likely outside of that code and not reproducible for us. It could be due to a system update, a Ruby update, or some configuration change. Regarding _"I tried to using `::gets` instead of `readline` to avoid `EOFError`"_ – instead of silencing the error you should try to figure out why it is occurring in the first place. `EOFError` indicates that your input is empty, i.e. that your piped commands don't generate any output. – Stefan Nov 04 '22 at 14:35

0 Answers0