1

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

0

2 Answers 2

1

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%
Sign up to request clarification or add additional context in comments.

2 Comments

Okey i was using echo, not return. Thank you!
Ah sorry, it must be exit(0) or exit(1). I just updated my answer.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.