Reputation: 6282
As is known, the Ruby's Kernel#spawn method executes the specified command and returns its pid. The method can accept either a whole command line as a single argument, a command name and any number of the command's arguments or an array where the first element is the command itself and the second is, according to the documentation, the strange variable argv[0]. As it turned out, the variable has nothing to do with the Ruby's ARGV[0].
What is this variable? What does it contain?
Thanks.
Debian GNU/Linux 6.0.2;
Ruby 1.9.3-p0.
Upvotes: 1
Views: 710
Reputation: 26144
I don't think it's a variable at all.
When executing a command (in the general case), the arguments go into argv[1]
to argv[*n*]
. The name of the command executed can be found in argv[0]
. (For Ruby applications, they will be placed in ARGV
, for C applications they can be accessed using the argc
and argv
arguments to main
.)
By default, argv[0]
will be the same as the command started. However, if you use following form:
exec(["alpha", "beta"])
The program alpha
will be executed, but it's argv[0]
will be beta
.
Upvotes: 3