【发布时间】:2013-12-19 20:25:36
【问题描述】:
在我的项目中,有一个脚本可以返回我必须在表格中显示的产品列表。
为了存储我使用IO.popen的脚本的输入:
@device_list = []
IO.popen("device list").each do |device|
@device_list << device
end
device list 是给我产品列表的命令。
我将@device_list 数组返回到我的视图,以便通过迭代来显示。
运行时出现错误:
Errno::ENOMEM (Cannot allocate memory):
for IO.popen
我在另一个脚本 device status 上只返回 true 和 false,但我得到了同样的错误:
def check_status(device_id)
@stat = system("status device_id")
if @stat == true
"sold"
else
"not sold"
end
end
我该怎么办?
【问题讨论】:
-
每当我看到 Rails 运行 shell 命令时,我都想知道权限问题。您确定用户 Rails 以有权运行脚本的身份运行吗?你可以从
rails console运行它吗?您可以从您的应用程序运行其他 shell 命令(例如ls)吗?我意识到错误将您指向记忆,但也许它只是在这里变得混乱。 -
你的机器内存不足吗?
-
@np_ 当我从
rails console运行这些命令时,它们运行良好。
标签: ruby-on-rails ruby ruby-1.8