|
Prev: HTTPS client library?
Next: Flushing Sockets in C?
From: Alex Vinokur on 26 Nov 2005 02:43 I tried to execute the following command line: strcpy (cmd, "ls"); strcpy (args[0], "ls"); strcpy (args[1], "-l"); strcpy (args[2], "*.c"); args[3] = NULL; execvp (cmd, args); However I have got an error message: ---------------------------- ls: '*.c': No such file or directory ---------------------------- How to pass arguments with '*' to execvp()? Thanks, -- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
From: Nils O. on 26 Nov 2005 02:33 Alex Vinokur wrote: > I tried to execute the following command line: > > strcpy (cmd, "ls"); > strcpy (args[0], "ls"); > strcpy (args[1], "-l"); > strcpy (args[2], "*.c"); > args[3] = NULL; > > execvp (cmd, args); > > However I have got an error message: > ---------------------------- > ls: '*.c': No such file or directory > ---------------------------- > > > How to pass arguments with '*' to execvp()? The shell is responsible for expanding pathnames containing * . So run a shell that runs ls -l *.c as in e.g. sh -c ls -l *.c
From: Pascal Bourguignon on 26 Nov 2005 03:36 "Alex Vinokur" <alexvn(a)users.sourceforge.net> writes: > I tried to execute the following command line: > > strcpy (cmd, "ls"); > strcpy (args[0], "ls"); > strcpy (args[1], "-l"); > strcpy (args[2], "*.c"); > args[3] = NULL; > > execvp (cmd, args); > > However I have got an error message: > ---------------------------- > ls: '*.c': No such file or directory > ---------------------------- > > > How to pass arguments with '*' to execvp()? Using opendir, readdir and fnmatch. You can also have a look at the sources of bash. -- __Pascal Bourguignon__ http://www.informatimago.com/
From: Alex Vinokur on 26 Nov 2005 05:50 "Pascal Bourguignon" <spam(a)mouse-potato.com> wrote in message news:87fypjvm8u.fsf(a)thalassa.informatimago.com... > "Alex Vinokur" <alexvn(a)users.sourceforge.net> writes: > > > I tried to execute the following command line: > > > > strcpy (cmd, "ls"); > > strcpy (args[0], "ls"); > > strcpy (args[1], "-l"); > > strcpy (args[2], "*.c"); > > args[3] = NULL; > > > > execvp (cmd, args); > > > > However I have got an error message: > > ---------------------------- > > ls: '*.c': No such file or directory > > ---------------------------- > > > > > > How to pass arguments with '*' to execvp()? > > 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) ? -- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
From: Pascal Bourguignon on 26 Nov 2005 06:21
"Alex Vinokur" <alexvn(a)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. -- __Pascal Bourguignon__ http://www.informatimago.com/ There is no worse tyranny than to force a man to pay for what he does not want merely because you think it would be good for him. -- Robert Heinlein |