PHP’s exec(), shell_exec(), and system() commands are supported in applications built with ExeOutput for PHP.
The following PHP code illustrates how to use these commands to run external EXE files, BAT (batch) files, and more. By default, a console window is displayed.
To run a batch file located in the same folder as the application’s EXE file:
In this sample, the exo_getglobalvariable PHP function returns the path to the folder where the EXE is located.
<?php
$mypath = exo_getglobalvariable('HEPublicationPath', '') . 'sample.bat';
echo exec($mypath);
?>For a console application, use the following:
<?php
system('cmd /c "'.dirname(__DIR__) . '\\test.bat"');
?>To run system commands:
<?php
echo system('echo | C:\\WINDOWS\\System32\\wbem\\wmic.exe path win32_computersystemproduct get uuid');
?>To run an EXE program in the background, you can use the following function:
<?php
function execInBackground($cmd) {
pclose(popen("start /B " . $cmd, "r"));
}
?>To display the contents of the current folder:
<?php
echo system("dir");
?>