我正在尝试在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文件中的内容
预先感谢:)
答案 0 :(得分:3)
您将要查看Open3
类,特别是capture2
或capture3
:
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")
上面所看到的,将使您的脚本运行capture3
,stdout
和stderr
运行。尽管status
仅返回capture2
和stdout
。 status
中还有其他有用的功能值得关注。
要了解为什么Open3
和exec
的行为方式,请阅读以下答案:Ruby, Difference between exec, system and %x() or Backticks