this is somewhat of a tricky question when it comes to "where should I place it?", but I assume a general problem behind it, which is why I am putting it on superUser.

I have a Doctrine script which is executed in a php file by calling:

exec('bin\doctrine.php.bat dbal:import import_data/mssql_data.sql'.' 2>&1', $output);

Since I am piping errors from STDERR to STDOUT and save it in $output, I get error messages.

Executing the script gives me:

php is not recognized as an internal or external command

Although I have added it to my system PATH variable:

(...)C:\Program Files\Microsoft\Web Platform Installer\;C:\PHP

C:\PHP is the correct path and doesn't contain a trailing "\" as mentioned here: php is not recognized as an internal or external command (windows 7).

Also, I can manually execute php scripts from CMD, using "php someFile.php", without problems. So I assume the PATH has been correctly adapted.

To be sure, I have also rebootet the machine with unchanged results.

I realize this could be a doctrine error, but since the error message looks like a general system problem, I hoped to find help here.

Currently I am kind of helpless and can only assume that, since the script is executed by php, it's running as the system user and thus doesn't get access to the PATH variable. But afaik this is only true for "normal" environment variables, since they are stored "per user". The PATH is a system variable and should thus be accessible by any user running the script, so it shouldn't matter. Correct?

The system is Windows Server 2012 R2.

Any suggestions and help are much appreciated!

  • Maybe the .bat script alters PATH? – gronostaj Aug 26 '14 at 9:59
  • The first file is: @ECHO OFF SET BIN_TARGET=%~dp0/../doctrine/orm/bin/doctrine.php php "%BIN_TARGET%" %* It fails in the third line, executing BIN_TARGET. I checked by alterting the file: @ECHO OFF SET BIN_TARGET=%~dp0/../doctrine/orm/bin/test.php php "%BIN_TARGET%" %* and executing with the contents of test.php being a simple Hello World echo. Problem persists :/ – Worp Aug 26 '14 at 11:00

After not being able to find a solution for this, we went ahead and passed the PHP path along to the Doctrine batch script:

For example: exec("bin\doctrine.php.bat \"".PHP_PATH."\php.exe\" orm:generate-proxies");

We then modified doctrine.php.bat like this: @ECHO OFF SET BIN_TARGET=%~dp0/../doctrine/orm/bin/doctrine.php %1 "%BIN_TARGET%" %2 %3 %4 %5

Simply adding our PHP_PATH as the first param before executing doctrine.

Thus it didn't matter if PHP was recognized as being in the path or not. An absolute path is ugly but it works...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.