正在像这样使用 ocra 构建 .exe ocra testing.rb -- sample
这里我将''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<mpl=default<mplcache=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 时,它总是采用与参数“样本”相同的值,因为它是硬代码。
C:\Users\shivaj\Downloads>testing.exe -- test1
它作为样本放置
请帮我解决这个问题,我只是制作了一个有问题的示例程序,但实际程序与它有更多关系。任何帮助表示赞赏。感谢您的帮助 !
最佳答案
我想这是因为您将参数分配给了一个变量,并且在构建 exe 时提供了一个参数。
我使用一些使用参数并使用 ocra 转换为 exe 的脚本。
我做的是以下内容
ARGV.each do|arg|
# do whatever with arg
end
然后,当您构建 exe 时,您不提供参数,代码将运行正常,因为 ARGV 将在那里但为空。
关于ruby-on-rails - Ocra 生成的 exe 不接受参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43332492/