我正在使用ubuntu 14.04。我在程序的main()顶部添加了以下代码,但在运行时我没有打印任何内容。
char const* masteruri = getenv("ROS_MASTER_URI");
if (masteruri!=NULL){
printf ("The current masteruri is: %s",masteruri);
}
char const* rosdis = getenv("ROS_DISTRO");
if (rosdis!=NULL){
printf ("\n The current rosdis is: %s",rosdis);
}
但是另一个程序中的相同代码给出了预期的结果
The current masteruri is: http://localhost:11311
The current rosdis is: indigo
我已经包含了stdlib.h并且我在etc / profile.d
中导出了变量答案 0 :(得分:0)
我不知道为什么,但是printf由于某种原因无法工作,我尝试了DEVLOG_INFO并注意到/etc/profile.d中导出的变量值可以通过两个程序返回getenv()。