父子环境变量 [英] parent child environment variables

查看:178
本文介绍了父子环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为子进程改变或环境变量传递回父进程?

Is it possible for the child process to change or pass back an environment variable to the parent process?

例如:

我有一个运行Access数据库序列的批处理文件。一旦数据库已通过其查询的运行,我想传递一个值回使用VBA批处理文件 - 但我似乎无法得到这个工作。

I have a batch file that runs a sequence of access databases. Once the database has run through its queries i want to pass a value back to the batch file using VBA - but i can't seem to get this to work.

我可以使用 getEnvironmentVariable 功能,但 SetEnvironmentVariable方法不似乎工作读取父变量。

I can read the parent variable by using the getEnvironmentVariable functions but the setEnvironmentVariable doesn't seems to work.

推荐答案

您VBA都会有自己的批处理环境调用它的副本。您可以在本地副本的值,但它会消失,一旦VBA返回控制你的批处理脚本。因此,答案是否定的,你不能做你直接想要的东西。

Your vba will have its own copy of the batch environment that called it. You can set a value in the local copy, but it will disappear once vba returns control back to your batch script. So the answer is no, you cannot do what you want directly.

你所想要做的是一个共同的需要。一个解决方案是将值写入到一个临时文件,然后父批处理脚本读取的值并删除临时文件。

What you want to do is a common need. One solution is to write the values to a temporary file and then have the parent batch script read the values in and delete the temp file.

您可以避开临时文件,如果你的VBA可以写入标准输出 - 我认为你可以,但我不能肯定。你的批处理脚本可以调用通过FOR / F数据库和处理标准输出输出。还有如何FOR / F分析输出很多的选择。

You can avoid a temporary file if your vba can write to stdout - I assume you can, but I'm not sure. Your batch script could call your database via FOR /F and process the stdout output. There are a lot of options for how FOR /F parses the output.

一般语法是:

for /f "options" %%A in ('yourCommand') do (REM process values using %%A)

键入 HELP FOR FOR /?在命令提示符下,得到充分的帮助的FOR命令。

Type HELP FOR or FOR /? from the command prompt to get full help on the FOR command.

这篇关于父子环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆