从c++中为Batch设置临时环境变量
Setting a temporary environment variable for Batch from C++
我正在实现一个小程序包,供批处理用户使用。这个包中几乎所有的东西都是用c++编写的,并从Java调用。
如何设置批处理文件使用的环境变量?
我试过使用这个:
JNIEXPORT void JNICALL METHOD_NAME(JNIEnv *env, jclass theclass, jstring key, jstring value) {
const char* thekey = env->GetStringUTFChars(key, false);
const char* thevalue = env->GetStringUTFChars(value, false);
std::string envvar;
envvar.append(thekey);
envvar.append("=");
envvar.append(thevalue);
_putenv(envvar.c_str());
env->ReleaseStringUTFChars(key, thekey);
env->ReleaseStringUTFChars(value, thevalue);
}
但是批处理文件没有看到任何新的变量。我应该使用system("set thing=value");
吗?
经过一番研究,我得出结论,子进程不能修改父进程的环境。
相关文章:
- docker 构建失败:无法设置环境变量
- 如何在不传递命令行参数的情况下在 c++ 中设置环境变量
- 在编译时为运行时设置环境变量
- 如何在提升构建中设置环境变量以进行提升单元测试框架?
- 如何设置Qt应用程序以使用类Unix系统的实际环境变量?
- 在 Visual Studio 2017 C++项目中设置调试/运行环境变量
- 以编程方式设置全球环境变量
- 将 c++ 代码中的当前用户环境变量设置为对其他进程(如 cmds)可见
- TCL文件无法获取通过代码设置的环境变量
- 如何使用CMakeLists.txt为我的可执行文件设置bash中的环境变量
- 为特定过程的特定运行设置环境变量
- 退出后从C++程序永久设置环境变量
- 为英特尔C++编辑器"GCC not found"设置环境变量时出现问题
- php-cgi环境变量设置
- 如何在Qt中以编程方式为当前进程设置环境变量
- 我已经设置了 CPUPROFILE 环境变量和链接的 -lprofiler。为什么 gperftools 不启动探查器?
- 如何在安装MinGW (Windows 32位)时设置环境变量PATH
- C/MATLAB API接口环境变量设置影响OS X中的其他应用程序
- 在Windows 7下运行MinGW gcc编译器,不设置环境变量
- 从c++中为Batch设置临时环境变量