0

I have a Windows10 Ubuntu bash environment set up. It has a few rubygems installed (without docker, bundler, without rvm, and also this is not rails). The script is working fine when I run it manually from inside the Ubuntu terminal, in the user home folder ~/

Now my goal is create a Windows Scheduled Task using the Task Scheduler application, to run the script daily, like I would with a crontab in Unix.

The action in this Scheduled Task is the challenge. In testing manually from the Windows CMD prompt, I got as far as:

C:\>C:\Windows\System32\bash.exe -c "ruby ~/myscript.rb"

That fails :

Traceback (most recent call last):
    2: from /home/lam/ruby/remind_prepare_dad_before_iterative_ends.rb:15:in `<main>'
    1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- tiny_tds (LoadError)

Above error tells me it cannot find my gem, TinyTDS. What do I add to the command line to make it find my gems?

Felix Ogg
  • 852
  • 7
  • 23
  • I used gem install, so with this answer: https://stackoverflow.com/questions/19072070/how-can-i-find-where-gem-files-are-installed/19072136 I could reference the INSTALLATION directory if i knew how. – Felix Ogg Dec 03 '18 at 12:20

2 Answers2

1

I found a crude workaround for my own problem: just install the gem from the same command line:

C:\>C:\Windows\System32\bash.exe -c "sudo gem install tiny_tds"

I had to re-install a few more gems I use in the same way.

After this, I put in a -C argument to start ruby in the right directory, like so:

C:\>C:\Windows\System32\bash.exe -c "ruby -C ~/ruby myscript.rb"

works like a charm. I suppose now I have duplicated gems floating in spaces on the machine, but we will address that issue if it ever becomes a problem. :-)

Felix Ogg
  • 852
  • 7
  • 23
0

Try bundle exec ruby ~/myscript.rb

David S.
  • 730
  • 1
  • 7
  • 23
  • yeah, make that "without docker, without rvm, and also this is not rails, and without bundler" – Felix Ogg Nov 30 '18 at 17:15
  • If you have a Gemfile using `bundle` will properly load the gems, if not then you have to install your dependencies globally and it should work. EDIT: Also, validate your `$PATH` in a bash session. – David S. Nov 30 '18 at 17:17
  • can you be more specific how to validate? i.e. what do I type and what should I expect? – Felix Ogg Nov 30 '18 at 17:20