-
May 3rd, 2004, 06:04 AM
#1
understanding commandline
Hello.
I have programmed MFC for more than 5 years and now it is a little bit funny for me, to program for commandline and understanding ist. So dont be angry because of stupid questions.
If I have this command line:
MyProg -Channels 14 -port 8000 -service console
And the program ist named MyProg
What can I expect exactly as argc and char* argv[] at the entrypoint main:
int main(int argc, char* argv[])
{
}
And can sombody explain, why I can expect these things?
Thanks for help.
M.D.
-
May 3rd, 2004, 07:06 AM
#2
Couldn't you just try, and print'em out?
Anyhoo:
// argc = the count of space separated "words" in the commandline:
argc = 7
// Each "word" has its own index in the argv array:
argv[0] = "MyProg"
argv[1] = "-Channels"
argv[2] = "14"
argv[3] = "-port"
argv[4] = "8000"
argv[5] = "-service"
argv[6] = "console"
-
May 4th, 2004, 01:23 PM
#3
argv[0] is usually the name of the program.
-
May 4th, 2004, 01:37 PM
#4
mwilliamson posted:
argv[0] is usually the name of the program
what could it be else than the name of the program?
**** **** **** **** **/**
-
May 5th, 2004, 04:51 AM
#5
Originally posted by Guysl
what could it be else than the name of the program?
Well, if you want to be exact you should say it is the name by which the program is called.
Example:
Code:
[treuss]src>cat foo.cc
#include <iostream>
int main( int argc, char* argv[] )
{
std::cout << "argv[0] is \"" << argv[0] << "\"" << std::endl;
}
[treuss]src>g++ -o foo foo.cc
[treuss]src>ln -s foo bar
[treuss]src>./bar
argv[0] is "./bar"
The program binary has the name "foo", but I call it via a symbolic link under the name bar.
-
May 5th, 2004, 05:52 AM
#6
treuss,
well, isn't a symbolic link supposed to be an alias name for
the program, which means it is a name of the program
(among other "names")?
**** **** **** **** **/**
-
May 5th, 2004, 06:04 AM
#7
Thank you for help.
I have never though it would be such an horror to program without MFC-Classes. I am too familliar with these classes. So the beginning is al little bit hard for me. So I dont see the wood for the threes. Sorry, for this banal question.
Your answers helped me a lot.
Thanks.
M.D.
-
May 5th, 2004, 11:52 AM
#8
Originally posted by Guysl
well, isn't a symbolic link supposed to be an alias name for the program
Yepp. Its an alias. So it is not the name (if there is such a thing). Point is that if you deliver software you usually expect that the binary is not renamed by the user who installs it. But you cannot rely on that argv[0] will hold exactly that name, because argv[0] could be "foo", "/usr/bin/foo", "C:\foo" or "bar".
This is of course rather academic, as I don't know why anybody would rely on argv[0] having a certain value...
-
May 5th, 2004, 01:12 PM
#9
Good point, treuss.
**** **** **** **** **/**
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|