I am on Windows 10 and have the following PHP code:
<?php
system("php -v");
?>
It is expected to output my PHP version as it does when I run php -v in my command prompt:
PHP 8.1.6 (cli) (built: May 11 2022 08:55:59) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
However, it is not giving any output at all.
Can someone guide me on how to fix this? Other commands such as python --version are returning the appropriate output through the system function, only php -v has this behavior.
UPDATE: I just tried system(".\~\..\..\xampp\php\php.exe -v"); so it uses the exact path of the PHP executable but still no luck. Again, running the same command in the command prompt returns the desired output for some reason.
UPDATE 2: Trying the update suggested by @hanshenrik seems to generate the following error: 'php' is not recognized as an internal or external command, operable program or batch file. string(31) "operable program or batch file.". I do have PHP in my path and using php -v in a normal command prompt in any directory gives me the relevant results, it's just that the system or (recently tested) passthru commands in PHP are not getting it to execute.