2

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

Ramilol
  • 3,394
  • 11
  • 52
  • 84
  • 1
    Do 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 Answers3

4

There are two choices, depending on what kind of program you are building.

  • If your program is a console mode program, use argc and argv parameters passed to your main().
  • If your program is a GUI mode program, use the pCmdLine parameter passed to your WinMain().

In either case, you can always use GetCommandLine().

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
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