argc and argv

From: userfriendly (thetrini_at_hotmail.com)
Date: 02/29/04


Date: 29 Feb 2004 07:58:28 -0800

Hi, I know its possible to get argv and argc easily when your commands
are typed in (cin), but how do you get the values for argv and argc
when you are reading them from a file, each line of the file being a
command for running a program. I am trying to do it using getline,
but it doesnt work correclty. here is some code. thank you.

while (!infile.eof())
    {
      int i = 1;
      argc = 0;
      infile.getline(process,sizeof(process));
      
      p1 = strtok(process, " ");
      argv[0] = p1;

I then run the tokenizer in a loop to fill in the rest of argv, but it
doesnt work correctly if there is a space in the directory name before
the args.
Eg. it will for for something like this:
c:\temp\notepad.exe /w test.txt

but not for this:
c:\temp 2\notepad.exe

any help is appreciated.



Relevant Pages

  • Re: argc and argv
    ... I know its possible to get argv and argc easily when your commands ... > but it doesnt work correclty. ... Quite apart from the code errors, what you are trying cannot easily work. ...
    (comp.lang.cpp)
  • Re: argc and argv
    ... I know its possible to get argv and argc easily when your commands ... > but it doesnt work correclty. ... It's a DOS issue. ...
    (comp.lang.cpp)
  • Re: exec script dies without error - help
    ... http because it only takes $argv. ... I have run the same commands that make is crash. ... other times they dont. ...
    (alt.php)
  • Re: Backed in to a wall
    ... >Neither one of thse commands work while being executed in the script, ... $argv on arrival at these commands. ...
    (comp.lang.tcl)
  • Re: use of argc and argv
    ... Claudio Varini wrote: ... What has cin to do with argc and ...
    (comp.lang.cpp)