我有一個循環,我在遠程機器上執行一系列命令:紅寶石,我怎麼能訪問外面做局部變量 - 循環結束
ssh.exec('cd /vmfs/volumes/4c6d95d2-b1923d5d-4dd7-f4ce46baaadc/ghettoVCB; ./ghettoVCB.sh -f vms_to_backup -d dryrun') do|ch, stream, data|
if #{stream} =~ /vmupgrade/
puts value_hosts + " is " + data
puts #{stream}
puts data
end
end
我想訪問#{流}和數據外端循環
我將不勝感激任何幫助。 謝謝,
嗨約爾格,
我實現了您的建議,但現在我得到錯誤:
WrapperghettoVCB.rb:49: odd number list for Hash
communicator = {ch: ch, stream: stream, data: data}
^
WrapperghettoVCB.rb:49: syntax error, unexpected ':', expecting '}'
communicator = {ch: ch, stream: stream, data: data}
^
WrapperghettoVCB.rb:49: syntax error, unexpected ':', expecting '='
communicator = {ch: ch, stream: stream, data: data}
^
WrapperghettoVCB.rb:49: syntax error, unexpected ':', expecting '='
communicator = {ch: ch, stream: stream, data: data}
^
WrapperghettoVCB.rb:76: syntax error, unexpected kELSE, expecting kEND
WrapperghettoVCB.rb:80: syntax error, unexpected '}', expecting kEND
對不起,這是用'符號'鍵'Hash's的新的Ruby 1.9'Hash'文字語法。只需用':foo => bar'替換所有'foo:bar'。 I.e .:'communicator = {:ch => ch,:stream => stream,:data => data}'。 – 2010-09-28 19:45:53