0

I have a case that i need to exit the batch (.bat) program while executing a php script inside.

for example, this is my php code echo.php

<?php echo "NOTHING TO DO" ?>

and then i create a batch file to run it, this is just an example of my logic, but this is not work

@title "ECHO TEST"
@echo off
D:
cd D:\xampp\htdocs
SET status = "D:\xampp\htdocs\echo.php"
echo Status is %status%
pause

expected output is

Status is NOTHING TO DO

the final is i just need to know how to put php cli output into a variable of batch file so i can do condition for it.

NoobnSad
  • 75
  • 3
  • 9

2 Answers2

0

You will need a for /f loop to parse the output of your php file. You have to modify your code, so it will do like this:

@title "ECHO TEST"
@echo off
cd /d D:\xampp\htdocs
for /f "delims=" %%A IN ('D:\xampp\htdocs\echo.php') do set "status=%%A"
echo Status is %status%
pause

Hope this helps!

double-beep
  • 5,031
  • 17
  • 33
  • 41
0

Thanks all for the response, so i got this solution loop untill the condition is meet with ur requirements

:loop

:: Parse token is like word, and delims mean like explode lol
:: Make parameter A for the output, and then define OUTPUT as the callback
FOR /F "tokens=* delims= " %%A IN ('PHP PATH TO YOUR ACTION') DO SET OUTPUT=%%A

:: If condition
IF "%OUTPUT%" == "YOUR OUTPUT" (
    exit
) else (
    goto :loop
)
:: PS, my english is not really good
NoobnSad
  • 75
  • 3
  • 9
  • `REM` is the comment command **not** `::` which is a malformed `goto` lable. – CatCat Dec 04 '18 at 19:42
  • thank you for information, but anyway my code is work with comment command like that :D – NoobnSad Dec 10 '18 at 09:01
  • Writing deliberately wrong code *is wrong* and IT WILL NOT WORK where a lable is illegal. Consider this batch file `For %%A in (*) do (` , `echo %%A` , `::test`, then `)`. It will **CRASH**. – CatCat Jan 07 '19 at 04:31
  • maybe this can be reference https://stackoverflow.com/questions/12407800/which-comment-style-should-i-use-in-batch-files – NoobnSad Jan 08 '19 at 09:47
  • One writes to spec, not to the internet. – CatCat Jan 08 '19 at 10:03