为什么从Ruby调用Bash命令会抛出错误?

3

我正在尝试使用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中切换调用的路径,似乎无法使其工作。
3个回答

5

它正在执行你的shell脚本但找不到wine。尝试设置wine安装的完整路径。

which wine

@Aidanc,你应该给出wine和你的exe文件(pngcrush.exe)的完整路径。 - Mr. Black

1

不要在命令周围加上引号。


1

你确认在命令行中键入 wine pngcrush.exe -brute drawable/feed_cl.png new/feed_cl.png 是有效的,是吗?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接