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