I’m using exec() for years on my PHP app (v8.3.14) on Apache 2.4, and used to add “2>&1” on the command lines to get the output and errors and display or log it.
But recently (few days) it starts failing on my PC and I found that it is the 2>&1 part that makes it fail. If I add it, the return code goes from 0 (ok) to 1 (error) and I can’t get the error message.
// simple example:
exec('ver',$out,$code); // -> code 0 and out ["Microsoft Windows [version 10.0.26100.3194]"]
exec('ver 2>&1',$out,$code); // -> code 1 and empty message
The command works on cmd prompt with and without 2>&1 so it seems to be a PHP problem. It’s like ‘2>&1’ is becoming part of the arguments passed to the executable (which fails because it cannot handle it) instead of an option for the system to handle the response.
I didn’t make changes on my PHP/Apache installation the last days. There was probably a minor Windows update, as often. Is anyone experimenting the same problem and have a solution?