i know how to Start process with argument but im trying to create a program that uses this arguments. for example IE8 uses Process::Start( "IExplore.exe","google.com"); as a argument to open new window with url google.com. i want my program to use the argument are send it but i don't know how to get the the argument. like Process::Start( "myprogram.exe","TURE"); i want my program to get the ture thanks in advance Rami
Asked
Active
Viewed 2,791 times
2
-
1Do you have an introductory C++ book? If you do, this is probably covered in one of the very first chapters. If you don't, you should consider getting one of the introductory books listed in [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list). – James McNellis Aug 08 '10 at 20:55
3 Answers
4
There are two choices, depending on what kind of program you are building.
- If your program is a console mode program, use
argc
andargv
parameters passed to yourmain()
. - If your program is a GUI mode program, use the
pCmdLine
parameter passed to yourWinMain()
.
In either case, you can always use GetCommandLine()
.

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
-
3GetCommandLine() is windows-specific though and not portable, so using argc/argv is usually to be preferred. – Frank Osterfeld Aug 08 '10 at 21:23
-
That's correct. I thought it was pretty clear that the OP is using Windows. – Greg Hewgill Aug 08 '10 at 21:38
2
Assuming you write your entry point something like this:
int main(int argc, char* argv[])
Then argc
is the number of arguments used to invoke your program and argv
are the actual arguments.
Try it out:
#include <cstdio>
int main(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
printf("%s\n", argv[i]);
}

Travis Gockel
- 26,877
- 14
- 89
- 116
-
If you're using the Windows entry point: `int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)`, then `lpCmdLine` is the command line and `nCmdShow` is the number of arguments. – Travis Gockel Aug 09 '10 at 02:08
-2
#include <stdlib.h>
...
system("IExplore.exe google.com");

Evgeny Lazin
- 9,193
- 6
- 47
- 83

Daniel
- 30,896
- 18
- 85
- 139