From: ara.t.howard@... Date: 2006-03-27T02:56:17+09:00 Subject: Re: String to array as command line On Mon, 27 Mar 2006, lubos wrote: > I have found the problem: > the correct version is : > > def command_line string > Marshal::load(IO::popen("ruby -r yaml -e' print > Marshal::dump(ARGV) ' -- #{ string }"){|io| io.read}) > end > > the problem was that I put the "-v" parameter in the string and it was > used by ruby itself and thus destroyed the marshaled stream... > the added "--" parametr avoid this behavior. > > Thanks, this is exactly what I was looking for.. ah - yes - good catch. i guess it goes without saying that this is somewhat expensive... but it should be portable. about the only other thing would be to dynamically determine which ruby to run instead of relying on the PATH setting require "yaml" require "rbconfig" def command_line string cline = lambda{|ruby| Marshal::load(IO::popen("#{ ruby } -r yaml -e' print Marshal::dump(ARGV) ' -- #{ string }"){|io| io.read}) } c = ::Config::CONFIG ruby = File::join(c["bindir"], c["ruby_install_name"]) << c["EXEEXT"] begin cline[ruby] # don't depend on PATH rescue cline["ruby"] # depend on PATH as fallback end end regards. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama