1

The story is like this:

  • After running a JUnit test campaign, I run a php script to get the variables $testsOK and $testsFailed.

  • In the same php script I have to add to environment variables "OK" and "FAILED" the numbers that I obtained just before in the same script. I used putenv, $_ENV["OK"]= ... even apache_setenv("OK",$testsOK), which of course does not work since I do not have a webserver, I only use PHP CLI.

  • I will have to use these environment variables "OK" and "FAILED" in windows batch command after the script was run.

On the putenv page on php.net (http://php.net/manual/en/function.putenv.php) someone says that: "putenv/getenv, $_ENV, and phpinfo(INFO_ENVIRONMENT) are three completely distinct environment stores. doing putenv("x=y") does not affect $_ENV; but also doing $_ENV["x"]="y" likewise does not affect getenv("x"). And neither affect what is returned in phpinfo()."

Therefore, none of these methods will help me. My question is: should I drop this method and try with another language? :-) or is there a way that I'm missing.

I would very much appreciate your help. Anca

1
  • You cannot set environment variables in another process and have them retained in the parent shell. That works nowhere. Commented Mar 22, 2011 at 21:15

1 Answer 1

1

You may wrap the invocation in a script, the PHP would return via stdout the values to be set; the script would then capture this output into the appropiate environment variables.

A very simplified version would be something like this.

@echo off
runtestcampaign
for /f %%a in ('php myscript.php') do (
  set OK=%%a
  set Fail=%%b
)
restofbat 
Sign up to request clarification or add additional context in comments.

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.