I have a c file I've compiled with a executable called "run"
And want to run it with a argv of testfile.txt that is in the uploads directory.
This here seems to work, but I don't understand why.
exec(__DIR__ . '/run uploads/testfile.txt',$output);
exec(__DIR__ . './run uploads/testfile.txt',$output);
You only need the
. when you're running a program without providing a pathname. If the program name doesn't contain
/, the shell searches for the program in
$PATH. By typing
./run, it tells it to look in the current directory rather than searching for it.
Since you're providing a full path to the program by prepending
__DIR__, it won't search for the program. It's not necessary to insert
. before the program name in this case, and it's resulting in an incorrect filename. It's adding
. to the last directory in
__DIR__, and that directory doesn't exist.