I have a script that allows a user to execute the makefile located in a certain directory. I do not know how to execute a file in another directory with the system() command. Here's what I have:

    if($dirname = opendir("$dir"))
    {
       while(false !== ($filename = readdir($dirname)))
       {
            if($filename == "Makefile")
                    system("make $dir");     
       }
    }

I know that system() call is not even close to being correct. Even if I do something like system('ls >output.txt') it does not work. I get no output and the file is not created. The only thing that works is something like system(ls).

Any advice?

Thanks!

    $dir = "/home/user/dir";
    
    if(file_exists($dir . "/Makefile")) {
        $output = `make --directory=$dir`;
    } else {
        echo "Couldn't find Makefile in $dir!";
    }
    
      Write a Reply...