From 6ba86ddde5156de8cca3f112cddc1209ee3f7bc6 Mon Sep 17 00:00:00 2001 From: Roque Pinel <1685896+repinel@users.noreply.github.com> Date: Thu, 21 Nov 2019 23:13:45 -0500 Subject: [PATCH] Silence Prince message `fin|success` Changes how the Prince command is executed and stdout is capture in order to hide the message `fin|success`. --- lib/princely/pdf.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/princely/pdf.rb b/lib/princely/pdf.rb index 76b7b2a..fc03b0a 100644 --- a/lib/princely/pdf.rb +++ b/lib/princely/pdf.rb @@ -1,3 +1,4 @@ +require 'open3' require 'timeout' module Princely @@ -69,9 +70,8 @@ def executable_options def pdf_from_string(string, output_file = '-') with_timeout do pdf = initialize_pdf_from_string(string, output_file, {:output_to_log_file => false}) - pdf.close_write result = pdf.gets(nil) - pdf.close_read + pdf.close result.force_encoding('BINARY') if RUBY_VERSION >= "1.9" result @@ -107,9 +107,10 @@ def initialize_pdf_from_string(string, output_file, options = {}) log_command path if options[:log_command] # Actually call the prince command, and pass the entire data stream back. - pdf = IO.popen(path, "w+") - pdf.puts string - pdf + stdin, stdout = Open3.popen3(path) + stdin.puts string + stdin.close + stdout end def log_command(path)