Process.spawn中的“错误的第一个参数”异常

时间:2017-09-04 16:14:28

标签: ruby windows

我正在尝试产生这样的过程

# name I get from network (I'm using webrick)
Process.spawn(name)

然而我最终得到了

ArgumentError: wrong first argument

但这有点奇怪。当我使用binding.pry在之前突破时 Process.spawn致电,这就是我得到的:

> name
=> "notepad.exe"
> name == "notepad.exe"
=> true
> Process.spawn(name)
ArgumentError: wrong first argument
from (pry):23: in `spawn`
> Process.spawn("notepad.exe")
=> 728
> Process.spawn(name.to_s)
=> 1416

所以我刚刚确认name等于"notepad.exe"Process.spawn 使用name调用时失败,使用"notepad.exe"调用时失败。它 使用name.to_s调用时也有效。有人可以解释一下会发生什么 上?

name"notepad.exe"都有UTF-8个编码(通过name.encoding验证) 并且namename.to_s都不是tainted?

我看了source code 但不知道发生了什么。

谢谢。

1 个答案:

答案 0 :(得分:2)

问题在于WEBrick::HTTPUtils::FormData定义了#to_ary。所以我将使用name.to_s解决这个问题。