Hello,

I have a problem that I hope you can help me out with.

I have a file "a.out", which is a C++ program compiled with g++. I'm trying to execute that program from PHP and read the output, but to no avail.

This is my code:

$fp = popen("./a.out","r");
while (!feof($fp)) echo fgets($fp,1024);
pclose($fp);

I have tried replacing "./a.out" with "a.out", "/fullpath/to/a.out", etc... and nothing works.

Am I missing something or is it not possible to execute .out files from PHP?

Thanks in advance.

    Any error messages displayed or logged? (You might want to turn on the display_errors option and set [man]error_reporting[/man] to E_ALL.)

    Does the web server user (not your personal user account) have read and execute permission on that file? (You may have to give it 766 permission.)

    Is [man]safe_mode[/man] in effect on your web host?

      Thanks for your reply.

      No error messages are displayed or logged, I set error_reporting to E_ALL and still nothing.

      I'm pretty sure the web server user has permissions. It's a dedicated server and I'm running it on the apache document root. I also tried setting permissions to 755, 766, etc. and still nothing.

      Safe_mode is Off.

      Any other ideas?

      🙁

        By the way, if I loging through SSH and go to the directory where the a.out file is, the command "./a.out" works just fine. It's PHP that's having problems executing it :/

          Maybe try something a bit simpler like [man]shell_exec/man just to see what happens?

            Nevermind, found the problem!

            It was a problem with shared libraries on the executable. It was running fine from SSH but not from PHP. I re-build the a.out file as static and now it works 😃

            Thank you!

              Write a Reply...