NSDictionary *envDic;
envDic = [[nsprocessInfo processInfo] environment];
if([[envDic allKeys] containsObject:@"LOGNAME"] ){ // 判断是否存在环境变量 LOGNAME
[mainTextField setStringValue:[envDic valueForKey:@"LOGNAME"] ] ; // 获得环境变量 LOGNAME
[seconTtextField setStringValue:@"How are you"];
}
ADC 中的参考文档如下:
Overview
The nsprocessInfo class provides methods to access @R_154_4045@ion about the current process. Each process has a single,shared nsprocessInfo object,kNown as process @R_154_4045@ion agent.
这个处理程序的代理包含:命令行参数,系统环境变量,主机名,进程名。
The process @R_154_4045@ion agent can return such @R_154_4045@ion as the arguments,environment variables,host name,or process name. The processInfo class method returns the shared agent for the current process—that is,the process whose object sent the message. For example,the following line returns the nsprocessInfo object,which then provides the name of the current process: Nsstring *processName = [[nsprocessInfo processInfo] processName]; The nsprocessInfo class also includes the operatingSystem method,which returns an enum constant identifying the operating system on which the process is executing. nsprocessInfo objects attempt to interpret environment variables and command-line arguments in the user's default C string encoding if they cannot be converted to Unicode as UTF-8 strings. If neither conversion works,these values are ignored by the nsprocessInfo object.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。