Suppressing stubborn console output on system calls in Ruby

180 views Asked by At

I'm calling imagemagik's convert program from within ruby to convert image types. I'm redirecting both stdout and stderr to /dev/null but I'm still getting console text. It only occurs when converting FROM webp so I suspect it's output from the Ubuntu webp package.

buffer = `convert -quiet "#{temp_dir}#{tmp_image_filename}" "#{temp_dir}#{new_image_filename}" > /dev/null 2>&1`

Output:

Decoded /tmp/magick-3658rrhNn7wh4IW2. Dimensions: 580 x 300 . Format: lossy. Now saving...
Saved file /tmp/magick-3658nGuNL-bzCkRA

Is this tty output? I can't figure out how to capture and suppress it. I added the quiet attribute to convert command line but it had no affect (another reason I suspect webp is the culprit). I've tried several other tips in my stackoverflow search with system, IO, wrapping in : $(...), etc to no avail. Any help?

Thanks! Eric

1

There are 1 answers

0
Eric M On BEST ANSWER

Question was answered in the comments. I moved to Open3.capture3 using a format like below and the console text from webp is captured.

stdout, stderr, status = Open3.capture3("convert -flatten \"#{$temp_dir}#{tmp_image_filename}\" \"#{$temp_dir}#{@image_filename}\"")