From: JJ Date: 2008-01-09T13:20:10+09:00 Subject: Re: Ruby's Kernel::exec (and system and %x) On Jan 8, 4:41 pm, thefed wrote: > On Jan 7, 2008, at 5:14 PM, Nobuyoshi Nakada wrote: > > > cmd = "C:/Program Files/..." > > exec([cmd, cmd]) > > > Citing from `ri exec': > > If the first argument is a two-element array, the first > > element is the command to be executed, and the second > > argument is used as the +argv[0]+ value, which may show up > > in process listings. > > But wouldn't that affect the program cmd, because it is having > something passed to it? No. This code exec([cmd, cmd]) is running cmd with no arguments. The second occurrence of "cmd" is what is actually passed in to the process as its program name (available to C programs via argv[0] in main(), for example). So with the two-item list, there is no shell interpretation. To add arguments, use exec([cmd, cmd], arg, arg) but that is the same as exec(cmd, arg, arg) simply because once you have at least two arguments to "exec", it behaves in the no-shell fashion anyhow. One could "trick" a program by running exec([cmd, "string"], arg, arg) and the program would execute, but see "string" as how it was invoked. This confuses some applications, but is possible. -JJ