I am trying to run execlp with find ... -exec ..., and the find program consistently tells me:
find: missing argument to `-exec'
What could be wrong? When I run find with these arguments on my shell, it succeeds.
My function calls follow (after looking at related SO threads, I have tried several arrangements of the argmuments):
execlp("find","find","/home/me","-exec","/usr/bin/stat", "{}", "\\;",NULL);
execlp("find","find","/home/me","-exec","/usr/bin/stat", "'{}'", "\\;",NULL);
execlp("find","find","/home/me","-exec","/usr/bin/stat", "{}", "';'",NULL);
execlp("find","find","/home/me","-exec","/usr/bin/stat {} \\;",NULL);
When you execute the command from C, you don't need the
\before;Using this syntax should work
When on the shell,
;marks the end of a command, and has to be escaped.execlpdoesn't go through the shell to execute a command, it does it immediately.Edit -- you actually only do one find so this part is not necessary
Moreover, the
execfamily replaces the current process with the requested command. So only the firstexeclpwill be executed.A solution is to
fork()for eachfind(one by one, waiting for the child process to end, otherwise the output will be a mix of all results).