# Cannot execute ruby files without wrapper in a cron

**URL:** <https://rubytalk.org/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/43557>\
**Category:** ruby-talk\
**Created:** [6 January 2008 21:29 UTC](https://rubytalk.org/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/43557 "2008-01-06T21:29:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Junkone](https://rubytalk.org/u/Junkone)\
**Post date:** [6 January 2008 21:29 UTC](https://rubytalk.org/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/43557/1 "2008-01-06T21:29:58Z")

</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)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from e:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:  
27:in `re  
quire'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from E:/TradingTools/CODE/ABScans.rb:3

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [6 January 2008 22:16 UTC](https://rubytalk.org/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/43557/2 "2008-01-06T22:16:49Z")

</div>

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

> **···**
>
> On Jan 6, 2008 10:29 PM, Junkone \<junkone1@gmail.com\> wrote:
> 
> > 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)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from e:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:  
> > 27:in `re  
> > quire'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from E:/TradingTools/CODE/ABScans.rb:3
> 
> --  
> [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://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Junkone](https://rubytalk.org/u/Junkone)\
**Post date:** [7 January 2008 00:00 UTC](https://rubytalk.org/t/cannot-execute-ruby-files-without-wrapper-in-a-cron/43557/3 "2008-01-07T00:00:00Z")

</div>

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

> **···**
>
> On Jan 6, 5:16 pm, Robert Dober \<robert.do...@gmail.com\> wrote:
> 
> > On Jan 6, 2008 10:29 PM, Junkone \<junko...@gmail.com\> wrote:
> > 
> > \> 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
> > 
> > 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- Hide quoted text -
> > 
> > - Show quoted text -
