From: Lloyd Zusman Date: 2001-03-31T14:40:04+09:00 Subject: [ruby-talk:13377] Re: Passing an array to `exec'? OOPS ... a couple of corrections (marked with "###", below): Lloyd Zusman writes: > I'd like to do the following: > > cmd = [ '/bin/ls', ARGV ] ### cmd = [ '/bin/ls' ].concat( ARGV ) > exec(cmd) > > However, this doesn't work, because the `exec' method cannot take an > array as an argument. > > I know that the following is possible: > > cmd = [ '/bin/ls', ARGV ] ### cmd = [ '/bin/ls' ].concat( ARGV ) > exec(cmd.join(' ')) > > However, this causes the command line passed to `exec' to be fed > to the shell, which I do not want. > > Is there any way to make ruby construct a proper argument list for a > method from an array? > > Thanks in advance. I also know that I can do this: cmd = [ '/bin/ls' ].concat( ARGV ) eval 'exec("' + cmd.join('", "') + '")' But is this the only way that I can get the behavior I want? It's rather inelegant, and seems inefficient. -- Lloyd Zusman ljz@asfast.com