如何在Ruby on Rails中执行.sh文件

时间:2019-04-20 01:17:04

标签: ruby-on-rails ruby sh

我正在尝试在Rails索引操作中执行.sh文件。

我尝试class MvcController { private MvcModel model; private MvcView view; public MvcController(MvcModel model, MvcView view) { this.model = model; this.view = view; model.addPropertyChangeListener(MvcModel.BATTERY, new BatteryListener()); model.addPropertyChangeListener(MvcModel.SPEED, new SpeedListener()); view.getSpeedSlider().addChangeListener(chngEvent -> { int value = view.getSpeedSlider().getValue(); model.setSpeed(value); }); view.getBatterySlider().addChangeListener(chngEvent -> { int value = view.getBatterySlider().getValue(); model.setBatteryPercentage(value); }); } public void init() { view.getSpeedSlider().setValue(10); view.getBatterySlider().setValue(100); model.setSpeed(10); model.setBatteryPercentage(100); } class SpeedListener implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { float speed = model.getSpeed(); view.setSpeed(speed); } } class BatteryListener implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent evt) { int batteryPercent = model.getBatteryPercentage(); view.setBatteryPercent(batteryPercent); } } } 它在终端中执行它,然后停止服务器!我不知道为什么 我尝试exec"sh app/controllers/file.sh"在浏览器中返回true,而不是.sh文件中的内容

预先感谢:)

1 个答案:

答案 0 :(得分:3)

您将要查看Open3类,特别是capture2capture3

SELECT tblusers.*, 
tblaffiliates.sForename AS sAffForename, 
tblaffiliates.sSurname AS sAffSurname, 
L.LastLogin
FROM tblusers 
LEFT JOIN tblusers AS tblaffiliates 
ON tblusers.nAffiliate_ID = tblaffiliates.nUser_ID 
LEFT JOIN 
(SELECT ID, MAX(logindate) AS 'LastLogin' FROM tbluserlogins GROUP BY ID) L
ON tblusers.nAffiliate_ID = L.ID;

如您在require 'open3' stdout, stderr, status = Open3.capture2("sh app/controllers/myscript.sh") 上面所看到的,将使您的脚本运行capture3stdoutstderr运行。尽管status仅返回capture2stdoutstatus中还有其他有用的功能值得关注。

要了解为什么Open3exec的行为方式,请阅读以下答案:Ruby, Difference between exec, system and %x() or Backticks