# Cannot execute ruby files without wrapper in a cron

**URL:** <https://www.ruby-forum.com/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/125196>\
**Category:** Ruby\
**Created:** [January 6, 2008, 10:30pm UTC](https://www.ruby-forum.com/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/125196 "2008-01-06T22:30:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 6, 2008, 10:30pm UTC](https://www.ruby-forum.com/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/125196/1 "2008-01-06T22:30:32Z")

</div>

whenever i try to execute a ruby file thro cron, i have to write a  
crapper to cd the folder of the ruby file and then execute it. it is  
such a hassle. what are the alternatives so that i dont have to write  
a wrapper. the prob that i get if i run them directly is that it tries  
to run in the same directory of the cron and cannot find the local  
libraries that my require statments have. how can i get ruby to  
execute the rb file in a specific directory. or is there any other  
option.

RUBY E:\TradingTools\CODE\ABScans.rb  
e:/ruby/lib/ruby/site\_ruby/1.8/xmlconfigfile.rb:646: warning:  
parenthesize argum  
ent(s) for future version  
e:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_re quire': no such file to load -- sendGmail (LoadError) from e:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 27:in`re  
quire’  
from E:/TradingTools/CODE/ABScans.rb:3

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 6, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/125196/2 "2008-01-06T23:17:22Z")

</div>

On Jan 6, 2008 10:29 PM, Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> e:/ruby/lib/ruby/site\_ruby/1.8/xmlconfigfile.rb:646: warning:

571/72 \> ruby -h  
Usage: ruby [switches] [–] [programfile] [arguments]  
-0[octal] specify record separator (\0, if no argument)  
-a autosplit mode with -n or -p (splits $\_ into $F)  
-c check syntax only  
-Cdirectory cd to directory, before executing your script  
-d set debugging flags (set $DEBUG to true)  
-e ‘command’ one line of script. Several -e’s allowed. Omit  
[programfile]  
-Fpattern split() pattern for autosplit (-a)  
-i[extension] edit ARGV files in place (make backup if extension  
supplied)  
-Idirectory specify $LOAD\_PATH directory (may be used more than  
once)  
-Kkcode specifies KANJI (Japanese) code-set  
-l enable line ending processing  
-n assume ‘while gets(); … end’ loop around your script  
-p assume loop like -n but print line also like sed  
-rlibrary require the library, before executing your script  
-s enable some switch parsing for switches after script  
name  
-S look for the script using PATH environment variable  
-T[level] turn on tainting checks  
-v print version number, then turn on verbose mode  
-w turn warnings on for your script  
-W[level] set warning level; 0=silence, 1=medium, 2=verbose  
(default)  
-x[directory] strip off text before #!ruby line and perhaps cd to  
directory  
–copyright print the copyright  
–version print the version

I guess the -I (that is “i”.upcase) is the option you need, AAMOF cron  
jobs are not exactly executed as in a login shell, I ignore(1) the  
details, but man cron will explain this in detail.  
Just for curiosity, which cron are you using and in which context  
(cygwin?).

HTH  
Robert  
(1) keep forgetting them is more precise 😉

–  
[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

Whereof one cannot speak, thereof one must be silent.  
Ludwig Wittgenstein

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [January 7, 2008, 1:00am UTC](https://www.ruby-forum.com/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/125196/3 "2008-01-07T01:00:52Z")

</div>

On Jan 6, 5:16 pm, Robert D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > to run in the same directory of the cron and cannot find the local  
> > quire’: no such file to load – sendGmail (LoadError)  
> > -Cdirectory cd to directory, before executing your script  
> > -s enable some switch parsing for switches after script name  
> > jobs are not exactly executed as in a login shell, I ignore(1) the  
> > Whereof one cannot speak, thereof one must be silent.  
> > Ludwig Wittgenstein- Hide quoted text -
> 
> - Show quoted text -

I am using python cron on windows and -I is just what the doc  
prescribed. its works beautifully.
