I have a strange situation with a very simple batch file which I want to run from PHP, and get the exit code of this.
If I run the batch script from cmd.exe
, echo %errorleve%
will return the correct exit code, in this case 12
.
From PHP script, exit code is 0
.
my_batch.bat file
@ECHO OFF
if "1"=="1" (
if "1"=="1" (
echo quitting
exit /B 12
)
echo anything
)
my_test.php
<?php
exec('my_batch.bat',$result,$exitcode);
echo $result[0];
echo '<br />';
echo $exitcode;
Output from cmd.exe
D:\tools\xampp\htdocs\test>my_batch.bat
quitting
D:\tools\xampp\htdocs\test>echo %errorlevel%
12
D:\tools\xampp\htdocs\test>
Output oh php:
quitting
0
Thank you for your support
EDIT 1
verry strange, if I change the code with this version, all works OK
my_batch.bat file
@ECHO OFF
if "1"=="1" (
if "1"=="1" (
echo quitting
SET MYERROR=12
GOTO:END
)
echo anything
)
:END
echo finished ... ERRORLEVEL "%MYERROR%"
exit /b %MYERROR%