-1

我正在使用 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 中导出了变量

4

1 回答 1

0

我不知道为什么,但是 printf 由于某种原因无法正常工作,我尝试了 DEVLOG_INFO 并注意到 /etc/profile.d 中导出的变量值可以由两个程序使用 getenv() 返回。

于 2017-10-26T16:47:21.597 回答