dongtun1872 2011-03-22 16:27
浏览 60
已采纳

在PHP中设置环境变量以便在Windows批处理命令中进一步使用

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条回答 默认 最新

  • douzhuangna6906 2011-03-22 19:30
    关注

    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 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败