2011-06-02 49 views
3

我试图使用Ruby一些图像执行以下bash命令:为什么从Ruby中调用Bash命令会引发错误?

class Pingcrush 
    def initialize 
    Dir.foreach('drawable') do |item| 
     next if item == '.' or item == '..' 
     # do work on real items 
     if item.end_with?(".png") then 
     %x["wine pngcrush.exe -brute drawable/#{item} new/#{item}"] 
     end 
    end 
    end 
end 
Pingcrush.new 

我在该目录的父既drawablenew,但是,当我试图运行该脚本我总是得到相同的错误:

sh: wine pngcrush.exe -brute drawable/feed_cl.png new/feed_cl.png: not found 

为什么会发生这种情况?我尝试转换我在Ruby中调用的路径,似乎无法完成此工作。

回答

5

它执行你的shell,但无法找到酒。尝试设置葡萄酒安装位置的完整路径。

which wine 
+0

我试过这个。似乎没有修复它。同样的错误。 – Aidanc 2011-06-02 14:38:59

+0

@Aidanc,你应该给葡萄酒和你的exe文件(pngcrush.exe)的完整路径。 – 2011-06-03 02:57:30

1

请勿在您的命令中加引号。

1

您已检查wine pngcrush.exe -brute drawable/feed_cl.png new/feed_cl.png是否从命令行输入时起作用,是不是?

相关问题