Dan,
I am trying to pass a variable to the backticks ``
function, but it is always interpreted as a string.def ping_host host
command=Array.new
command[0]=`ping host`
puts
puts command
end
First off, it is unclear what you are trying to do with the
"command=Array.new" line. You are currently creating an array, and then
setting the first element of the array to the result of "`ping host`".
Unless you plan to do something with the rest of the array, you can get
rid of this line and change the next line to "command = `ping host`".
Now, as to your real question, what you're looking for is:
command = `ping #{host}`
And once I do that, how can I get the results into an array?
It depends on how you want to split the resulting string into an
array. If you want the array to contain one "line" per element, you can
split the string using String#split:
command = `ping #{host}`.split($/)
Note that you might need to deal with CR ("\r") characters at the
end of the lines too.
I hope this helps.
- Warren Brown