Skip to content

Commit

Permalink
Output any eventual stderr from commands
Browse files Browse the repository at this point in the history
The `compare` command-line tool operates in the sense that it outputs
it's info to stderr, which is very strange, but we would like to support
that. This way, people could do:

  compare = MiniMagick::Tool::Compare.new(false)

  # Do something with compare ...

  $stderr = StringIO.new
  compare.run
  output = $stderr.string
  $stderr = STDERR

It's not really pretty, but I think this is the best we can do, since
using stderr should be ultimatively fixed in ImageMagick.

Fixes #257
  • Loading branch information
janko committed Oct 25, 2014
1 parent 40c2010 commit 0bdd2ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mini_magick/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def run(command)
fail MiniMagick::Error, stderr
end if @whiny

$stderr.print(stderr)

stdout
end

Expand Down
6 changes: 6 additions & 0 deletions spec/lib/mini_magick/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
allow(subject).to receive(:execute).and_return(["stdout", "", 127])
expect(subject.run(%W[foo])).to eq "stdout"
end

it "prints to stderr output to $stderr in non-whiny mode" do
subject = described_class.new(false)
allow(subject).to receive(:execute).and_return(["", "stderr", 1])
expect { subject.run(%W[foo]) }.to output("stderr").to_stderr
end
end

describe "#execute" do
Expand Down

0 comments on commit 0bdd2ae

Please sign in to comment.