View Full Version : ARGV / ARGC or any other ARG_ thing
Springbov
December 27th, 2005, 09:22 PM
What the heck is ARGV or ARGC I'm not quite sure what they are or what there for, can someone fill me in?
rob
December 29th, 2005, 04:35 AM
argv contains command line argument values. argc contains the number of command line values.
Hope this helps!
Springbov
December 29th, 2005, 01:05 PM
can you use it in a sentance?
ya know like
if ARGV == somethin
blah blah blah
end
bluetechnx
December 30th, 2005, 11:07 PM
Typically, programs that we write need to interact with the outside world somehow (the underlying OS, a remote computer). A program can communicate within itself using methods to pass around information, or classes, or variables.
To interact with the outside world requires something else. Typically, programs are invoked from the command line of an operating system (or the 'shell window'). We can pass data into our program and use it:
for instance under windows or Linux I could write:
firefox http://www.yahoo.com
This would load firefox and tell firefox to take me to Yahoo's main page.
http://www.yahoo.com
is a command line argument. The command line arguments are typically placed into a vector or Array. So 'argv' is the argument vector that holds values passed into a program from the command line. Most languages also have an 'argc' which stands for 'argument count' which holds an integer that says how many arguments were passed into the program.
In the C language:
> program.exe 1 2 3
argv = [program.exe, 1, 2, 3]
argc = 4
In C the 'program.exe' is the 1st element of the argv array.
In Java the main method of a program is:
public static void main(String[] args){ ... }
There is no agrv, or argc. But, an args. It is a String array which using the above example program would yield:
args = ["1", "2", "3"]
Java does not put the program name into the 1st args element...unlike C's argv above.
So...argv and argc are ways to pass data into your program from the outside world.
Here is a small example in Ruby:
if ARGV.size != 0 then
print "We got data!!!\n"
ARGV.each do |argument|
print "#{argument}\n";
end
else
print "We got no data :(, feed mee!!\n"
end
rob
December 31st, 2005, 01:16 AM
Wow, another wonderful post by bluetechnx! If you have any questions about command line arguments, they should be answered by this :)
Thanks againe bluetechnx!
sheefo
January 3rd, 2006, 07:00 AM
Finally someone can explain what ARGV means and as a bonus, an explanation of what ARGC means.
Thanks!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.