I am migrating a web function from a to-be-decommissioned Windows 2003 server running PHP 5.2.6 to a Windows 2012 server running PHP 7.3.9.
On the original server, the following PHP code would execute:
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Exec("cmd /c ".$filePath);
$sStdOut = $oExec->StdOut->ReadAll;
$sStdOut would then be parsed to inform the user of the outcome of the batch file (absolutely path'd in $filePath). The batch file itself would run an rsync.
On the new server, this code will not execute, even though I turned on COM / .NET by adding [COM_DOT_NET] extension=php_com_dotnet.dll
into the end of php.ini. $sStdOut would simply be an empty string, although $WshShell var_dumps as an object(com) and $oExec var_dumps as an object(variant).
I have also tried the numerous exec, shell_exec, etc. functions available in PHP. None of them execute the batch file that executes the rsync. As to specific functions and return values:
exec($filePath, $sStdOut) -> empty array for $sStdOut
exec("C:\WINDOWS\system32\cmd.exe cmd /c START " . $filePath, $sStdOut); -> waiting, then 500 error
exec('start /B / C ' . $filePath, $sStdOut); -> empty array for $sStdOut
exec("powershell -Command '[batch file name]'", $sStdOut); -> empty array for $sStdOut [I placed the batch file in the same directory as the PHP file to see if a relative file path would work]
$sStdOut = shell_exec($filePath) -> null for $sStdOut
$sStdOut = passthru($filePath); -> null for $sStdOut
$sStdOut = popen($filePath, 'r');
$read = fread($sStdOut, 2096);
pclose($sStdOut); -> stream resource for $sStdOut, empty string for $read
$r = pclose(popen($filePath, 'r')); -> int 1 for $r
$sStdOut = system("cmd.exe /c " . $filePath); -> empty string for $sStdOut
Essentially I have reviewed the answers to these three questions (among many other sources), and tried everything suggested in those three questions. No luck.
I also replaced spaces with underscores in the directory names leading up to the batch file, and added Everyone with execute access to the directories and the batch file itself. Again, no luck.
Oddly, I can execute "dir" as the $filePath in several of the examples listed above (I haven't re-tried them all), and get directory-related information back! Based upon that, I added the batch file's location to the Windows Path and tried to run it with just the batch file's name, but still no luck.