Reputation: 27866
I've made a Rake task for local dev that will build the project, start watching it for auto-compilation, and also start up a Thin server to see the compiled app.
I implemented Foreman to allow for setting up local ENV variables, which the project is now depending on. It works great - except it needs to also work on Windows.
My solution was to parse the .env files and manually set the vars in I start the server, ala:
$ MY_ENV_VAR=12345 ruby -rubygems app.rb
It works great when I execute it myself by hand. But if I try to execute that command via my Rake task - sh %{MY_ENV_VAR=12345 ruby -rubygems app.rb}
, it fails:
Command failed with status (127): [MY_ENV_VAR=12345 ruby -rubygems app.rb...]
I've tried executing it with sh %{}
, exec
, system
, %x{}
, and backticks with no luck. Any suggestions?
Upvotes: 2
Views: 1288
Reputation: 156434
Try using Kernel#system
with the env
argument:
env = {'FOO' => '123'}
cmd = 'echo $FOO'
system(env, cmd) # => prints "123", returns true
Upvotes: 4