Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute multiple commands on console through unix shell

I am currently trying to figure out if it is possible to run multiple commends within one line on a rails console through Unix shell or within a ruby script.

For Example:

exec('echo p = Product.first;b = Billing.first|rails c')

When I tried something similar to the example, it would always try to execute the two commands before launching console.

Hope this make sense and appreciate any help I can get.

Thanks in advance!

like image 839
jhwang Avatar asked Nov 04 '25 15:11

jhwang


1 Answers

Yes you can do this

From a unix shell prompt:

echo 'p = Product.first; b = Billing.first' | rails c

From the rails console itself, or a ruby script I guess:

exec(%Q{echo 'p = Product.first; b = Billing.first' | rails c})

It's probably worth asking why you want to do this though. Could you use a rake task?

like image 134
Devin Howard Avatar answered Nov 07 '25 11:11

Devin Howard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!