getenv

AppData / Similar for all OS : C++?

。_饼干妹妹 提交于 2020-07-10 01:45:32
问题 I'm looking to store some "preferences" for my C++ application. Under windows I know I have to use the "AppData" folder, but I need the equivalent for Linux and OsX. Is there some library or portable way to get such information in C++ ? Here is the code I use currently: #ifdef VD_OS_WINDOWS LPWSTR wszPath = NULL; HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, NULL, &wszPath); _bstr_t bstrPath(wszPath); std::string strPath((char*)bstrPath); CoTaskMemFree(wszPath);

Supervisor not using /etc/environment

烈酒焚心 提交于 2020-06-17 05:36:13
问题 I have an script in PHP that prints an environment variable set in /etc/environment with getenv. It works fine when I execute it manually, but when is executed by supervisor, it doesn't work. I don't want to put manually this environment variable on supervisor conf file, I want it to read /etc/environment correctly. Any help? Thanks in advance 回答1: As it says in supervisord config files documentation: supervisord config documentation In the section environment: Note that the subprocess will

Supervisor not using /etc/environment

99封情书 提交于 2020-06-17 05:35:17
问题 I have an script in PHP that prints an environment variable set in /etc/environment with getenv. It works fine when I execute it manually, but when is executed by supervisor, it doesn't work. I don't want to put manually this environment variable on supervisor conf file, I want it to read /etc/environment correctly. Any help? Thanks in advance 回答1: As it says in supervisord config files documentation: supervisord config documentation In the section environment: Note that the subprocess will

Supervisor not using /etc/environment

跟風遠走 提交于 2020-06-17 05:35:16
问题 I have an script in PHP that prints an environment variable set in /etc/environment with getenv. It works fine when I execute it manually, but when is executed by supervisor, it doesn't work. I don't want to put manually this environment variable on supervisor conf file, I want it to read /etc/environment correctly. Any help? Thanks in advance 回答1: As it says in supervisord config files documentation: supervisord config documentation In the section environment: Note that the subprocess will

“'getenv': This function or variable may be unsafe.” - really?

被刻印的时光 ゝ 提交于 2020-04-12 19:46:13
问题 I'm using MSVC to compile some C code which uses standard-library functions, such as getenv() , sprintf and others, with /W3 set for warnings. I'm told by MSVC that: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS Questions: Why would this be unsafe, theoretically - as opposed to its use on other platforms? Is it unsafe on Windows in practice? Assuming I'm not writing security-oriented code - should I

php操作redis

我的梦境 提交于 2020-03-07 01:02:15
**php.ini文件添加:extension=php_redis.dll 重启php, phpinfo可以看到redis则证明安装成功** php连接redis测试 <?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379);//serverip port $redis->auth('mypassword');//my redis password $redis ->set( "test" , "Hello World"); echo $redis ->get( "test"); php操作redis函数封装 1 /** 2 * 如果不传入$host和$port默认读取Laravel环境变量的参数 3 * redis Set/setex封装,可直接传入数组,可设置过期时间 written:yangxingyi 4 */ 5 function RedisSet($key,$value,$expire=0,$host='',$port=''){ 6 if(!$key||!$value) return false; 7 $host = $host?$host:getenv('REDIS_HOST'); 8 $port = $port?$port:getenv('REDIS_PORT'); 9 $redis = new

Go 每日一库之 godotenv

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-27 15:02:54
简介 twelve-factor应用提倡将配置存储在环境变量中。任何从开发环境切换到生产环境时需要修改的东西都从代码抽取到环境变量里。 但是在实际开发中,如果同一台机器运行多个项目,设置环境变量容易冲突,不实用。godotenv库从.env文件中读取配置, 然后存储到程序的环境变量中。在代码中可以使用读取非常方便。godotenv源于一个 Ruby 的开源项目dotenv。 快速使用 第三方库需要先安装: $ go get github.com/joho/godotenv 后使用: package main import ( "fmt" "log" "os" "github.com/joho/godotenv" ) func main() { err := godotenv.Load() if err != nil { log.Fatal(err) } fmt.Println("name: ", os.Getenv("name")) fmt.Println("age: ", os.Getenv("age")) } 然后在可执行程序相同目录下,添加一个.env文件: name = dj age = 18 运行程序,输出: name: dj age: 18 可见,使用非常方便。默认情况下,godotenv读取项目根目录下的.env文件,文件中使用key = value的格式

使用C语言获取linux系统相关信息

五迷三道 提交于 2020-01-10 10:47:07
最近在写shell的时候,涉及到了获取环境变量参数和本地计算机相关信息,包括计算机设备名,用户名的信息,在这里简单总结一下。 获取环境变量各项参数,可以直接使用getenv函数。man中关于getenv函数的声明如下: #include <stdlib.h> char *getenv(const char *name); 函数中,参数name 为环境变量的名称, 如果该变量存在则会返回指向该内容的指针. 环境变量的格式为name=value。执行成功则返回指向该内容的指针, 找不到符合的环境变量名称则返回NULL。 这里我使用环境变量获取用户名称和当前目录为例,首先我们知道在环境变量中,用户名保存在“LOGNAME”中,而当前目录保存在"PWD"中,所以函数调用应该为 getenv(“LOGNAME”) getenv(“PWD”); 所以,简单的测试程序就出来了,程序源码如下: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 int main(int argc,char **argv) 6 { 7 char *name; 8 char *path; 9 10 name = getenv("LOGNAME"); 11 path = getenv("PWD"); 12 13 printf(

获取真实IP地址

[亡魂溺海] 提交于 2020-01-02 05:04:11
/** * 获得用户的真实IP地址 * * @return string */ function getRealip() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (isset($_SERVER)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */ foreach ($arr AS $ip) { $ip = trim($ip); if ($ip != 'unknown') { $realip = $ip; break; } } } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $realip = $_SERVER['HTTP_CLIENT_IP']; } else { if (isset($_SERVER['REMOTE_ADDR'])) { $realip = $_SERVER['REMOTE_ADDR']; } else { $realip = '0.0.0.0'; } } } else { if

Strange behaviour for setenv & getenv in OS X Yosemite

你说的曾经没有我的故事 提交于 2019-12-31 04:25:07
问题 When I set an environment variable launchctl setenv FOO test I can fetch the value by launchctl getenv FOO which returns me 'test', but a simple echo $FOO doesn't substitute, the result is empty. In same terminal as well as in new terminal. Background: Yosemite 10.10 doesn't support /etc/launchd.conf anymore for system wide settings, so Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra? looks pretty promising, but I need the access to the