【发布时间】:2022-01-03 03:15:07
【问题描述】:
我的目标是为 PATH 变量添加一个程序路径,以便程序的不同部分可以通过仅指定其名称来启动它,就像这样
int main()
{
system("export PATH=%PATH%;/home/user/Workspace/myproject/build/bin/mybinary");
system("echo $PATH");// <-- the PATH is changed
//a far place in code
system("mybinary"); // <-- this should run the executable, but it can't find it
return 0;
}
这甚至可以做到吗?
【问题讨论】:
-
使用
setenv设置环境变量。对于 Windows,它似乎是_putenv。