0

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

9
  • 1
    Have you tried using Open3? Backticks are only suitable for quick'n'dirty hacks IMO. Commented Nov 6, 2020 at 22:03
  • No I haven't, looks like a good option. There's actually an example with convert in the docs LoL! I'll report back... THX! Commented Nov 6, 2020 at 22:09
  • 1
    Open3 will also save you from launching a shell (which will parse the command line and then exec convert) and leave you open to unpleasant quoting and escaping issues that can cause a lot of problems unless you're very careful. Open3 won't involve a shell so a lot of problems just go away. Commented Nov 6, 2020 at 22:14
  • Open3 is the way to go. Backticks are a dirty hack and honestly shouldn't even be allowed in Ruby without a special flag (ruby --yolo perhaps?). They're exceptionally dangerous if used incorrectly. Commented Nov 6, 2020 at 23:15
  • using Open3.capture3 produces the same results. The convert output (more likely the webp output) bleeds thru to the console... Commented Nov 7, 2020 at 1:17

1 Answer 1

1

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

require "open3"
stdout, stderr, status = Open3.capture3("convert -flatten \"#{$temp_dir}#{tmp_image_filename}\" \"#{$temp_dir}#{@image_filename}\"")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.