From: Stefan Lang Date: 2005-12-18T21:58:09+09:00 Subject: Re: Spawning On Sunday 18 December 2005 13:43, Steve Litt wrote: > On Sunday 18 December 2005 04:46 am, Florian Frank wrote: > > Steve Litt wrote: > > >I converted the array of arguments to a string, and it worked. > > > But it should have worked the other way too. What am I missing? > > > > exec *argarray > > Confirmed! Thanks Florian. > > Now I can run a command with several words quoted together to make > one argument. > > Curious -- what does the asterisk do to make it work when it didn't > work without the asterisk. What does the asterisk do? I know it > doesn't mean "the contents of this address" -- that's another > language :-) It flattens the array (argarray) into an argument list. This means the first element of argarray becomes the first argument to exec, the second element of argarray becomes the second argument to exec and so on. The following irb session demonstrates this: ########################################################## irb(main):001:0> def m(arg1 = nil, arg2 = nil, arg3 = nil) irb(main):002:1> p arg1 irb(main):003:1> p arg2 irb(main):004:1> p arg3 irb(main):005:1> end => nil irb(main):006:0> m nil nil nil => nil irb(main):007:0> m(1, 2, 3) 1 2 3 => nil irb(main):008:0> ary = [1, 2, 3] => [1, 2, 3] irb(main):010:0> m(ary) [1, 2, 3] nil nil => nil irb(main):011:0> m(*ary) 1 2 3 => nil irb(main):012:0> ary = [1, 2] => [1, 2] irb(main):013:0> m(ary) [1, 2] nil nil => nil irb(main):014:0> m(*ary) 1 2 nil => nil Regards, Stefan