27
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails,Rubyでシェルを実行したい!

Posted at

#Railsでシェルが使えるか気になったので調べてみました

##具体的な使い方

system記法

system('ls')
lsコマンドが実行されます

%記法

%x( "echo 'hello world'" )
hello worldが出力されます

バッククォート記法

`echo 'こんにちは'`
こんにちはが出力されます

##シェルスクリプトも実行できる
試しにブラウザからRSpecのテストを実行できるか試してみました

hoge_controller.rb
system("bash app/controllers/test.sh")
test.sh
bundle exec rspec
ブラウザからテストが実行できました
  hogehoge
  hogehoge


2 examples, 0 failures

###:zap:使い方によっては開発の幅が広がりそうです:zap:

27
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?