通过命令行将变量传递给Ruby脚本 [英] Pass variables to Ruby script via command line
本文介绍了通过命令行将变量传递给Ruby脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows上安装了RubyInstaller,我正在运行 IMAP同步,但我需要使用它来同步数百个帐户。如果我可以通过命令行将这些变量传递给它,我可以更好地自动化整个过程。
I've installed RubyInstaller on Windows and I'm running IMAP Sync but I need to use it to sync hundreds of accounts. If I could pass these variables to it via command line I could automate the whole process better.
# Source server connection info.
SOURCE_NAME = 'username@example.com'
SOURCE_HOST = 'mail.example.com'
SOURCE_PORT = 143
SOURCE_SSL = false
SOURCE_USER = 'username'
SOURCE_PASS = 'password'
# Destination server connection info.
DEST_NAME = 'username@gmail.com'
DEST_HOST = 'imap.gmail.com'
DEST_PORT = 993
DEST_SSL = true
DEST_USER = 'username@gmail.com'
DEST_PASS = 'password'
推荐答案
这样的东西:
ARGV.each do|a|
puts "Argument: #{a}"
end
p>
then
$ ./test.rb "test1 test2"
或
v1 = ARGV[0]
v2 = ARGV[1]
puts v1
puts v2
这篇关于通过命令行将变量传递给Ruby脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文