从PHP脚本exec()执行时无法从gradle获取输出

I am trying to build an Android application by executing Gradle from a PHP script using exec(), but there is no response, so I am unable to see why the build fails.

When executing the applications gradle wrapper from the terminal (SSH), the whole process works fine, using the following commands:

x:/path/to/project/$ ./gradlew assembleRelease
x:/path/to/project/$ ./gradlew assembleRelease --debug --stacktrace
x:/path/to/project/$ ./gradlew assembleRelease --debug --stacktrace > output.txt

The output works fine and I am able to troubleshoot any possible problems. When executing gradle from a PHP-script, there is no output.

// array for the output to be dumped into
$output_array = array();

// $result is empty (tried with stacetrace, debug and an output file)
$result = exec("cd /path/to/project && ./gradlew assembleRelease", $output_array);

// nothing displayed
var_dump($output_array);

There is no way of me telling where the problem is. I have checked that the required environment variables ($GRADLE_HOME and $ANDROID_HOME) are set using getenv() and they point to the correct path.

Any help would be great!

I'm no linux specialist, but it seems you launch it (ssh) from "~/path/to/project" (~ meaning your home path).

In php, you're trying to launch it from "/path/to/project" (absolute path from root folder).

try to replace your second command by "ls" so you'll see where you are... and compare with where you should be!