Found this nowhere else.
I have a batch file which calls a PHP file (php.exe - f file.php).
I'm blocked as i want to pass the PHP output (0 or 1) to the batch file.
Any idea on how to do this? Thanks
In PHP write:
<?php
echo 'Done';
exit(0);
// Use a value >= 1 for errors
//exit(1);
Then use the %ERRORLEVEL% variable within the batch file to get the result (error level) from PHP.
@echo off
php.exe -f test.php
echo %ERRORLEVEL%
in the .bat file you can assign any output to the variable like this:
FOR /F "usebackq tokens=*" %%x IN (`php.exe -f test.php`) do (SET "VARIABLE=%%x")
echo result is %VARIABLE%
VARIABLE is an arbitrary variable name inside the batch
usebackq parameter allows to put whole command in the back quotes (`) and use double quotes (") inside as parameters.