如何在可可中读取环境变量? [英] How can I read a environmental variable in Cocoa?

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

问题描述

如何读取用户设置的环境变量?

How could I read an environmental variable that a user has set?

我是Mac(可可)台式机开发的新手,我正在构建一个我可以用来访问亚马逊的s3服务的小工具。

I'm new to desktop development on the Mac (cocoa), and I am building a little tool that I can use to access amazon's s3 service.

我在.bash_profile中设置了环境变量,但是无论用户在哪里输入它,我都希望它能够正常工作(.bashrc,.bash_profile或.profile等)。

I set my environmental variables in my .bash_profile, but I want this to work regardless of where the user entered it (.bashrc, .bash_profile or .profile etc).

推荐答案

查看环境方法。它返回环境的NSDictionary,例如对于PATH

Look at the environment method on a NSProcessInfo. It returns a NSDictionary of the environment so e.g. for PATH

NSString* path = [[[NSProcessInfo processInfo]environment]objectForKey:@"PATH"];

这篇关于如何在可可中读取环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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