I've to find with a script an executable named Test that take as argument a path, and execute it. I'm doing this with this line:
find -name Test -exec {} path \;
In Test I got an execl:
execl("./Test1","Test1",(char*)0);
perror("Exec failed");
exit(EXIT_FAILURE);
where Test1 is in the same directory of Test . Executing Test "manually" everything goes fine, but using the line written above I have a Exec failed: No such file or directory error.
What's wrong ?
find executes Test from the directory you are executing find. If you can change the code for Test, then put the absolute path of Test1:
execl("/home/myuser/some/path/Test1","Test1",(char*)0);
perror("Exec failed");
exit(EXIT_FAILURE);
Or you can use -execdir instead of -exec:
find -name Test -execdir {} path \;
From find manpage:
-execdir: Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With