Return Value from CMD via Ruby

ruby

#1

I am trying to see if there is any way to return a value from cmd/batch in my ruby code.

I found this:
http://sketchucation.com/forums/viewtopic.php?f=180&t=35618

and in this example,
listing = %x[dir]
the cmd window pops up and runs, but my variable (listing) is empty


#2

You probably need to do a bit moreā€¦ e.g

dir=Dir.pwd
tmp="#{rand}.tmp"
fil=File.join(dir, tmp)
system("dir > #{fil}")
until File.exist?(fil)
end
puts listing=IO.read(fil)
File.delete(fil)

#3

What SU version Matt ?

There was one version that was broken but it is now fixed.
I had posted a quick fix which TIG had cleaned up and posted over at SCF, I think.

Remember that @TIG, a version or two ago. (It basically did a temp file fix.)


#4

16.1.1449


#5

Strange, same version and works fine for me under Win 7.