title: Piping email from Postfix to Ruby task error
body: <p>I'm trying to pipe mail from postfix to a rails tasks. I've got this working successfully when just piping to a vanilla ruby script, but when switching to a rails task I get the following error in the mail.log from Postfix:</p>
  
  <blockquote>
    <p>(Command died with status 1: "/usr/local/bin/rake". Command output: /usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in <code>to_specs': Could not find rake (&gt;= 0) amongst [] (Gem::LoadError)  from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in</code>to_spec'  from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in <code>gem'  from /usr/local/bin/rake:22:in</code>' )</p>
  </blockquote>
  
  <p>Here is the piping line from master.cf</p>
  
  <blockquote>
    <p>email-task unix    -       n       n       -       2       pipe
      flags=Xhq user=appuser directory=/home/myapp/application/ argv=/usr/local/bin/rake RAILS_ENV=production myapp:process_email</p>
  </blockquote>
  
  <p>Running the command <code>which rake</code> returns <code>/usr/local/bin/rake</code> so I have verified I have the correct rake path.</p>
  
  <p>I've tried setting <code>ENV['PATH']</code> inside of the .rake file to <code>/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games</code> and I've also tried cd'ing to the rails app directory in the pipe command but still causes the same error. I've done bundle install and update etc.</p>
  
  <p>Any help is greatly appreciated...thank you!</p>
  
  <p><strong>UPDATE</strong>
  I tried using bundle exec rake etc as suggested but am now getting this error:</p>
  
  <blockquote>
    <p>Command died with status 127: "/usr/local/bin/bundle". Command output: bundler: command not found: rake Install missing gem executables with bundle install</p>
  </blockquote>
  
  <p>I've tried adding gem 'rake' to the Gemfile as well. I'm assuming bundler can't find the Gemfile?</p>
  
  <p><strong>UPDATE (FIXED)</strong>
  So the command that finally worked was the following:</p>
  
  <blockquote>
    <p>email-task unix    -       n       n       -       2       pipe
      flags=Xhq user=appuser directory=/home/myapp/application/ argv=/usr/local/bin/bundle exec /usr/local/bin/rake RAILS_ENV=production mytask</p>
  </blockquote>
  
  <p>It was a combination of errors on my part.</p>
  
  <ol>
  <li>Full paths need to be used for bundle and rake</li>
  <li>app name is not needed in the task param for rake since the directory is being selected before executing</li>
  <li>A side issue: an old version of ruby was being used which caused an unrelated gem error after executing the postfix pipe</li>
  </ol>
  
  <p>Appreciate the help everyone.</p>