来自Ruby的系统调用

max*_*fry 1 ruby

如何在Ruby中调用终端调用?

我可以在我的Rails程序中运行"rake db:migrate VERSION = ...."吗?

fl0*_*00r 5

使用"`"引号:

`rake db:migrate VERSION=....`
Run Code Online (Sandbox Code Playgroud)

要么 system

system("rake db:migrate VERSION=....")
Run Code Online (Sandbox Code Playgroud)

您也可以使用此表示法:

%x[rake db:migrate VERSION=...]
Run Code Online (Sandbox Code Playgroud)

另见http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html