【发布时间】:2019-11-05 09:54:59
【问题描述】:
我需要通过 php 设置一些环境变量并从 windows cmd 访问它们。从 cmd 我用call php\php.exe install.php 0 调用php 然后install.php 将设置一些环境变量。当install.php 的执行完成时,我尝试从父 cmd 获取这些变量。但是 cmd 无法获取这些值。
这是我的install.php:
<?php
$config = json_decode(file_get_contents('tmp/config.json'), true);
foreach ($config[$argv[1]] as $segment=>$details){
putenv("targetFolder=$segment");
putenv("targetLink=$details[link]");
}
echo getenv('targetFolder');
结果如下:
%targetFolder% 应该返回 servers
【问题讨论】:
-
Call用于同一脚本中的其他批处理文件或标签,不用于第三方可执行文件。请删除它。
标签: php batch-file cmd command-line-interface