0

Is it possible to create a ruby script that can execute rails commands?

Like:

rails_start.rb:

Class RailsStart
    #Start rails server
    rails server
end
Rails beginner
  • 14,321
  • 35
  • 137
  • 257

2 Answers2

4

You can always shell out.

system('rails server')

or

`rails server` # backticks
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • Is it possible to define path to rails? So you can fire up multiple rails servers for apps. And where did you find this documentation for system? – Rails beginner Jan 28 '13 at 19:22
  • It's [Kernel#system](http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-system). No, you can't fire multiple servers this way. Unless you fork or multi-thread. See also [Dir#chdir](http://www.ruby-doc.org/core-1.9.3/Dir.html#method-c-chdir) – Sergio Tulentsev Jan 28 '13 at 19:25
  • :) http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby – Rails beginner Jan 28 '13 at 19:30
2

The easiest way is to put backticks around the command:

`rails server`

But what are you trying to do?

Zach Kemp
  • 11,736
  • 1
  • 32
  • 46