Ocra 生成的 exe 不接受参数



使用 ocra 构建.exe,就像这样ocra testing.rb -- sample

这里我将"样本"作为参数传递给下面的代码并构建一个 exe

require "selenium-webdriver"
$var = ARGV[0]
driver = Selenium::WebDriver.for :chrome
wait = Selenium::WebDriver::Wait.new(:timeout => 20)
puts $var

driver.navigate.to "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier"
sleep 5
input = driver.find_element(:id, "Email")
input.send_keys($var)
button = driver.find_element(:id, "next")
button.click
sleep 5

这里的问题是,在构建.exe之后,当我尝试通过传递不同的参数(值(来运行 exe 时,它总是将与"sample"相同的值用于参数,因为它是硬代码。

C:UsersshivajDownloads>testing.exe -- test1

它作为样本

请帮我解决这个问题,我只是制作了一个有问题的示例程序,但实际程序与此有关。任何帮助不胜感激。谢谢你的帮助!

我想

这是因为您将参数分配给一个变量,并且在构建 exe 时提供了一个参数。

我使用一些使用参数并使用 ocra 转换为 exe 的脚本。

我做的是以下

ARGV.each do|arg|
  # do whatever with arg
end

然后,当您构建 exe 时,您不提供参数,代码将运行良好,因为 ARGV 将在那里但为空。

目前不受

Ocra: https://github.com/larsch/ocra/issues/48

最新更新