This project is archived and is in readonly mode.

#4249 open
Andreas Mayer

[rails3 beta] "rails runner" can't be used in shebang lines

Reported by Andreas Mayer | March 21st, 2010 @ 11:23 PM | in 3.0.6

In Rails 2.3, I used the following line as shebang line for my scripts that should run in a Rails environment:

#!/usr/bin/env /path/to/my/app/script/runner

so exec("/usr/bin/env", "/path/to/my/app/script/runner", "./my-script.rb") was called and it worked.

In Rails 3.0.0beta1, the script/runner has been merged into the rails tool and as I understand it, I should call it as follows:
$ rails runner ./my-script.rb which works.

But, when I want to use the runner as a shebang line (as "rails runner -h" tells me:

You can also use runner as a shebang line for your scripts like this:
-------------------------------------------------------------
#!/usr/bin/env /path/to/my/app/script/rails
Product.find(:all).each { |p| p.price *= 2 ; p.save! }
-------------------------------------------------------------

) it doesn't work because:

1) The given shebang from rails runner tells me:

$ ./my-script.rb
Error: Command not recognized
Usage: rails COMMAND [ARGS]
...

because "rails" alone is not enough, it should be "rails runner"

2) I can't use "#!/usr/bin/env /path/to/my/app/script/rails runner" because parameters don't get separated in shebang lines, so
exec("/usr/bin/env", "/path/to/my/app/script/rails runner", "./my-script.rb"); is called which returns

$ ./my-script.rb
/usr/bin/env: /path/to/my/app/script/rails runner: file or directory not found

3) So I would have to use #!/path/to/my/app/script/rails runner the the parameters are correct but shebangs doesn't execute scripts => env is needed

So my only possibility would be a wrapper script, i.e. I would have to re-write script/runner that calls "rails runner" or to always call "rails runner script.rb" instead of "./script.rb" directly.

So:
1) Please fix the output of "rails runner -h". The suggested shebang doesn't work.
2) Maybe re-introduce script/runner?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages