# Problems with system("...") method in Rails

**URL:** <https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690>\
**Category:** Rails\
**Created:** [February 1, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690 "2010-02-01T15:05:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![christoph\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@christoph\_j](https://www.ruby-forum.com/u/christoph_j)\
**Post date:** [February 1, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690/1 "2010-02-01T15:05:53Z")

</div>

Hi there,

since two days or so my application doesn’t seem to execute the system  
method. I use it for generating thumbnails like:

```
def create_thumb(field,image_name)

  thumb_name = "..."
  path = "..."

  # call ImageMagick method from console
  command = "convert -thumbnail 120x120 " + path + image_name + " " 

```

- 

path + thumb\_name  
logger.info(“UPLOAD: before converting to 120x120 with  
#{command}”)  
system(command)  
…

```
end

```

The output to the logger is correct. When I execute the command string  
in  
the console (rails console or linux console) it works. But it seems not  
to  
work inside my Rails controller, which is really weird. It just don’t  
gets  
executed. I don’t get any error messages, any. Where else can I look?

Thanks for any help.

Chris

---

<div class="post-metadata">

**Author:** ![christoph\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@christoph\_j](https://www.ruby-forum.com/u/christoph_j)\
**Post date:** [February 1, 2010, 3:11pm UTC](https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690/2 "2010-02-01T15:11:45Z")

</div>

On Feb 1, 2:04 pm, Christoph J.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The output to the logger is correct. When I execute the command string in  
> the console (rails console or linux console) it works. But it seems not to  
> work inside my Rails controller, which is really weird. It just don’t gets  
> executed. I don’t get any error messages, any. Where else can I look?

Have you looked at the return value of system and $?

Fred

---

<div class="post-metadata">

**Author:** ![christoph\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@christoph\_j](https://www.ruby-forum.com/u/christoph_j)\
**Post date:** [February 1, 2010, 3:25pm UTC](https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690/3 "2010-02-01T15:25:12Z")

</div>

Thank Fred,

didn’t know about that possibility. But unfortunately the result is 0.  
So  
it’s really bad magic to me. Am trying to set the command path manually.  
Maybe that works.

---

<div class="post-metadata">

**Author:** ![christoph\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@christoph\_j](https://www.ruby-forum.com/u/christoph_j)\
**Post date:** [February 1, 2010, 3:50pm UTC](https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690/4 "2010-02-01T15:50:57Z")

</div>

Seems that I had to write the full path to convert. That might be cause  
by a  
problem I had with rmagick and had to install ImageMagick in two  
different  
ways (from source and from rpm) at the same time. It had screwed the  
path to  
convert. But somehow the rails console and linux console had no problem  
with  
the path, only a controller method.  
When I removed all the comments and the loggin’ calls I didn’t work  
again.  
So I left them. Somewhere along the ‘path’ there must be a problem. When  
I  
solve that I gonna tell you.

---

<div class="post-metadata">

**Author:** ![christoph\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/76d3ee/32.png) [@christoph\_j](https://www.ruby-forum.com/u/christoph_j)\
**Post date:** [February 1, 2010, 5:21pm UTC](https://www.ruby-forum.com/t/problems-with-system-method-in-rails/182690/5 "2010-02-01T17:21:44Z")

</div>

On 1 Feb 2010, at 14:49, Christoph J. wrote:

> Seems that I had to write the full path to convert. That might be cause by a problem I had with rmagick and had to install ImageMagick in two different ways (from source and from rpm) at the same time. It had screwed the path to convert. But somehow the rails console and linux console had no problem with the path, only a controller method.  
> When I removed all the comments and the loggin’ calls I didn’t work again. So I left them. Somewhere along the ‘path’ there must be a problem. When I solve that I gonna tell you.

You could easily be running as a different user which could cause $PATH  
to have different values.

Fred
