Re: How to pass arguments with '*' to execvp()?

From: Alex Vinokur (alexvn_at_x-privat.org)
Date: 11/26/05


Date: 26 Nov 2005 15:23:47 +0100


"Pascal Bourguignon" <spam@mouse-potato.com> wrote in message news:87br07ven4.fsf@thalassa.informatimago.com...
> "Alex Vinokur" <alexvn@x-privat.org> writes:
> >> Using opendir, readdir and fnmatch.
> > [snip]
> >
> > OK.
> > I found sample at http://docs.hp.com/en/B2355-90694/fnmatch.3C.html
> >
> > -----------------------
> > pattern = "*.c";
> >
> > while(dp = readdir(dirp)){
> > if((fnmatch(pattern, dp->d_name,0)) == 0){
> > /* do processing for match */
> > ...
> > }
> > }
> > -----------------------
> >
> > But how to apply that to passing args to execvp (cmd, args) ?
>
> You implement the "do processing for match" part.
[snip]

Something like?

---------------------------
strcpy (cmd, "ls");
strcpy (args[0], "ls");
strcpy (args[1], "-l");
// strcpy (args[2], "*.c");
args[3] = NULL;

pattern = "*.c";
  while(dp = readdir(dirp))
 {
     if((fnmatch(pattern, dp->d_name,0)) == 0)
    {

       strcpy (args[2], )dp->d_name);
       // stuff withh forks
       execvp (cmd, args);
       // stuff

    }
}
---------------------------

But in this case there will be several process created by execvp().
Of course, we need the only process created by execvp().

-- 
 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn