# Shell cmd fails from Rails (not from CLI & Ruby script)

**URL:** <https://www.ruby-forum.com/t/shell-cmd-fails-from-rails-not-from-cli-ruby-script/165369>\
**Category:** Rails\
**Created:** [April 13, 2009, 8:21am UTC](https://www.ruby-forum.com/t/shell-cmd-fails-from-rails-not-from-cli-ruby-script/165369 "2009-04-13T08:21:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [April 13, 2009, 8:21am UTC](https://www.ruby-forum.com/t/shell-cmd-fails-from-rails-not-from-cli-ruby-script/165369/1 "2009-04-13T08:21:57Z")

</div>

Rails 2.3.2, OS X 10.5.6

I am using the backtick method to run a shell command (happens to be  
ImageMagick stuff). The command works fine when I use it directly in  
Terminal. The command work fine if I extract the code out of Rails and  
put it into a text.rb file. From inside a Rails app it fails.

I’m still trying to understand the nature of the failure, but if I use  
2\>&1 at the end of the command, I can log an error message:  
“dyld: Library not loaded:  
/ImageMagick-6.5.0/lib/libMagickCore.2.dylib”

Googling not helping with that one, but I have checked that the file  
does exist, and AFAICT my profile file has the correct info re: the  
paths. And, there’s the thing that the command actually works from CLI  
and a plain Ruby script.

I have logged everything I can think of. I have even hard coded the  
entire shell command inside the Rails app.

Just can’t figure out why the difference when the code is run inside a  
Rails app.

Any ideas?? Thanks.

–gw

The test code…

#!/usr/bin/env ruby

class MagickImage

def initialize(real\_image\_path)  
@real\_file\_path = real\_image\_path  
@magick\_bin = “/usr/local/ImageMagick/bin/”  
end

def width  
img\_width = “”  
if @real\_file\_path && FileTest.exists?(@real\_file\_path)  
img\_width = `#{@magick_bin}/identify -format "%w" #{@real_file_path}`  
img\_width.strip! unless img\_width.nil?  
img\_width = “” if img\_width.nil?  
end  
return img\_width  
end

end

p MagickImage.new("/Users/greg/Desktop/goodfood.jpg").width

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [April 13, 2009, 8:54am UTC](https://www.ruby-forum.com/t/shell-cmd-fails-from-rails-not-from-cli-ruby-script/165369/2 "2009-04-13T08:54:56Z")

</div>

Greg W. wrote:

> Rails 2.3.2, OS X 10.5.6
> 
> I am using the backtick method to run a shell command (happens to be  
> ImageMagick stuff).  
> I’m still trying to understand the nature of the failure, but if I use  
> 2\>&1 at the end of the command, I can log an error message:  
> “dyld: Library not loaded:  
> /ImageMagick-6.5.0/lib/libMagickCore.2.dylib”

aarrrgggghhhhh.

Stupid IM binaries require a symlink at the root of the startupdrive.  
_lame!_

– gw
