Is there any way to tell if shell_exec is actually doing anything? I have it working fine for simple things like cd and ls but when I tried to do something a little more complicated it doesn't look like it's doing anything.

Here's one such command that's not working

$output = shell_exec('apktool d -f $file_name');
echo "<pre>Output :<br />$output</pre>";

apktool is something to reengineer android applications. The regular shell command I enter is identical to what I am putting into shell_exec but it isn't working.

Additional things to note:
I know php.ini has safe_mode off and it is not listed in disable_functions

    Well for one, this:

    $output = shell_exec('apktool d -f $file_name');

    is telling apktool to look for a file that begins with a dollar sign followed by 'file_name' - that's probably not going to work (unless you have a file named as such, of course).

    Also, try using exec() (man page: [man]function.exec[/man]) for a little more debug info. Specifically, try capturing the return status and outputting it as well.

      bradgrafelman;10981400 wrote:

      Well for one, this:

      $output = shell_exec('apktool d -f $file_name');

      is telling apktool to look for a file that begins with a dollar sign followed by 'file_name' - that's probably not going to work (unless you have a file named as such, of course).

      You're right about that! Unfortunately it still didn't work. 😕

      Also, try using exec() (man page: [man]function.exec[/man]) for a little more debug info. Specifically, try capturing the return status and outputting it as well.

      Here is what I got when I used exec, I don't know what to make of it: cmd returned 127, and output: array(0) { }

        it occurred to me to me to redirect the output to stderr.

        $output = system($cmd ." &> test.txt ");

        I'm getting

        exec: java: not found

        So the good news is that I know what the problem is and it's the same problem I originally thought it was. Bad news is I have no idea how to fix it because I'm trying to do this on my website and I don't have the ability to just install java on the server.

          cagagnon wrote:

          I don't have the ability to just install java on the server

          Sounds like you've outgrown the abilities of shared hosting and need to look into something that gives you a little more control (VPS, etc.).

            so is there anything I can do in the meantime to test all this php?

              Run it all on your local PC instead of a remote webserver (assuming that you have more control over the former than you do the latter)?

                Yeah only problem is I haven't yet been able to get php working correctly on my mac. I also have a virtual linux box. I guess tomorrow I'll work on just testing it locally until I can get it onto a server.

                Thanks for the help

                  It may be that you do have java installed and available on your hosting (unlikely though) but the path environment is different for Apache thatn it is for you. Try specifying the full path to the Java runtime (if you can't find it but you can log in via a terminal to the server run 'whereis java' and it should give you the full path)

                    Ashley Sheridan;10981454 wrote:

                    It may be that you do have java installed and available on your hosting (unlikely though)

                    Actually, I would say that it is very likely that this is the issue, since it sounds like the OP may be using shared hosting (and I don't know of any shared hosts that have java installed and available for their customers).

                      I didn't see where he mentioned shared hosting, so I went on the assumption of the next most likely reason. I do agree though, finding shared hosting with Java support, not bloomin' likely!

                        Ashley Sheridan;10981472 wrote:

                        I didn't see where he mentioned shared hosting, so I went on the assumption of the next most likely reason. I do agree though, finding shared hosting with Java support, not bloomin' likely!

                        yeah, I've just been testing it locally for the time being and everything is working fine. When I redirected errors with stdout I found out that the problem is exactly what I thought the problems was from the start--there was no java on the site I was testing it on. Lame, but not a huge deal in the grand scheme of things because that is not where it will end up.

                        thanks for all the help though.

                          Write a Reply...