通过unix shell在控制台执行多个命令

时间:2022-03-11 20:48:20

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.

我目前正在试图弄清楚,是否可以通过Unix shell在rails控制台的一行中或在ruby脚本中运行多个推荐。

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!

提前谢谢!

1 个解决方案

#1


3  

Yes you can do this

是的,你可以这么做

From a unix shell prompt:

来自unix shell提示符:

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

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

从rails控制台本身,或者从ruby脚本中:

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?

也许值得问一下你为什么要这么做。你能使用rake任务吗?

#1


3  

Yes you can do this

是的,你可以这么做

From a unix shell prompt:

来自unix shell提示符:

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

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

从rails控制台本身,或者从ruby脚本中:

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?

也许值得问一下你为什么要这么做。你能使用rake任务吗?