在对Ruby模块函数的调用中设置选项

在对Ruby模块函数的调用中设置选项,ruby,open4,Ruby,Open4,考虑一下Ruby的open4中的这个片段: def spawn arg, *argv argv.unshift(arg) opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {}) argv.flatten! cmd = argv.join(' ') getopt = getopts opts ignore_exit_failure = getopt[ 'ignor

考虑一下Ruby的open4中的这个片段:

  def spawn arg, *argv
    argv.unshift(arg)
    opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {})
    argv.flatten!
    cmd = argv.join(' ')


    getopt = getopts opts

    ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
    ignore_exec_failure = getopt[ 'ignore_exec_failure', !getopt['raise', true] ]
    exitstatus = getopt[ %w( exitstatus exit_status status ) ]
    stdin = getopt[ %w( stdin in i 0 ) << 0 ]
    stdout = getopt[ %w( stdout out o 1 ) << 1 ]
    stderr = getopt[ %w( stderr err e 2 ) << 2 ]
    pid = getopt[ 'pid' ]
    timeout = getopt[ %w( timeout spawn_timeout ) ]
    stdin_timeout = getopt[ %w( stdin_timeout ) ]
    stdout_timeout = getopt[ %w( stdout_timeout io_timeout ) ]
    stderr_timeout = getopt[ %w( stderr_timeout ) ]
    status = getopt[ %w( status ) ]
    cwd = getopt[ %w( cwd dir ) ]

也许这只是一个已经熟悉
open4
模块的人的问题。

您需要以这种方式传递参数:

open4.spawn cmd, 'ignore_exit_failure' => true
如果不指定,它会将
ignore\u exit\u failure
设置为
quiet
参数的值

open4.spawn cmd, 'quiet' => true

如果没有指定它,它会将
ignore\u exit\u failure
设置为
false

Show-us
getopts
方法源我想我认为这是一个标准的Ruby模块。不幸的是,这似乎不起作用。我从spawn收到了同样的抱怨:
/usr/share/ruby-rvm/gems/ruby-1.9.3-p0/gems/open4-1.3.0/lib/open4.rb:361:in
spawn:cmd失败,状态信号来自/usr/share/ruby-rvm/gems/ruby-1.9.3-p0/gems/open4-1.3.0/lib/open4.rb:384:in
block in-in-in-in-in-in-in-in-in-in-in-background'
cookiecaper,你能不能用完整的代码更新这个问题来调用
open4
(创建实例,传递参数)我给open4的创建者发了电子邮件,但没有得到回复。我已经放弃了这种方法。谢谢你愿意帮忙。如果你还好奇的话,这些代码都可以在网上找到。
open4.spawn cmd, 'quiet' => true