Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate exit value in batch file 1

Status
Not open for further replies.

MissyEd

IS-IT--Management
Feb 14, 2000
303
GB
Hi

I'm pretty new to PHP to excuse the newbie question.

I have a PHP file which I'd like to run on a schedule. On exit() it returns a number which is 0 for "All OK" and anything else for an error.

I've tried evaluating the ERRORLEVEL in the batch file but it comes back as 0. Below is my test:

@echo off
c:\php\php.exe -q c:\test\world.php

IF ERRORLEVEL 0 GOTO OK
IF ERRORLEVEL 1 GOTO NOTOK

:OK
ECHO "OK"
GOTO END

:NOTOK
ECHO "NOT SO GOOD"
GOTO END

:END

And this is the test PHP file:
#!/usr/bin/php -q
<?php
exit(1);
?>

Any suggestions appreciated.

"There are only two lasting bequests we can hope to give our children; one of these is roots, the other wings" - Hodding Carter
 
I can't get your code or my own to behave any better. Instead of using return values, maybe try setting an environment variable in your script and having the batch file react to the value of the variable?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Surely if your PHP code executes correctly,(whatever it is told to do) it will return a 0, if for instance there was a typo and the page didnt complete correctly, it theoretically would return the correct errorlevel ?



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thats brilliant sleionir214. Worked a treat. I need to know if the program executed correctly as I am dealing with an external web service that occassionally times out. If it does, I need to wait a little longer before re-running the script. This was the last piece of the puzzle, so Im v.grateful :)

"There are only two lasting bequests we can hope to give our children; one of these is roots, the other wings" - Hodding Carter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top