PHP exec() not executing batch files
Question
I tried googling for this issue and found many people with the same problem but no solution.
$result = exec("C:\\Ruby191\\bin\\lessc.bat less\\$file", $output);
Here result
is an empty string and output
an empty array. Same thing with:
$result = exec("cmd /c C:\\Ruby191\\bin\\lessc.bat less\\$file", $output);
I am sure the path is correct; I am sure exec() is enabled.
I tried exec
, shell_exec
, system
and none work.
lessc is less CSS.
EDIT
The apache error log says:
'"ruby.exe"' is not recognized as an internal or external command, operable program or batch file.
Solution
I found out the problem; I installed ruby just for this and added it to my PATH
environment variable, and it started working immediately for command prompts.
However it didn't work for PHP, so I decided to restart my computer. After that it worked.
OTHER TIPS
First chdir("C:\Ruby191\bin\"), then run lessc.bat.