将dos变量从dos批处理文件传递给ruby脚本[重复]

时间:2021-06-15 23:33:39

Possible Duplicate:
Pass variables to ruby script via command line

可能重复:通过命令行将变量传递给ruby脚本

I am trying to pass the HOSTNAME as a parameter into a ruby script. Is this possible? This is what I believe should work, but it doesn't.

我试图将HOSTNAME作为参数传递给ruby脚本。这可能吗?这是我认为应该工作的,但事实并非如此。

%h% = HOSTNAME
ECHO %h%

ruby this.rb %h%
pause

And the ruby code is

红宝石代码是

val = ARGV[0]

puts "Value is #{val}"

1 个解决方案

#1


0  

You could set an environment variable in DOS and access it from your Ruby script. It would be something like:

您可以在DOS中设置环境变量并从Ruby脚本访问它。它会是这样的:

set h = HOSTNAME
ECHO %h%

ruby this.rb
pause

Ruby code:

val = ENV["h"]

puts "Value is #{val}"

#1


0  

You could set an environment variable in DOS and access it from your Ruby script. It would be something like:

您可以在DOS中设置环境变量并从Ruby脚本访问它。它会是这样的:

set h = HOSTNAME
ECHO %h%

ruby this.rb
pause

Ruby code:

val = ENV["h"]

puts "Value is #{val}"