getenv

Environment Variables in Python on Linux

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Python's access to environment variables does not accurately reflect the operating system's view of the processes environment. os.getenv and os.environ do not function as expected in particular cases. Is there a way to properly get the running process' environment? To demonstrate what I mean, take the two roughly equivalent programs (the first in C, the other in python): #include #include #include int main(int argc, char *argv[]){ char *env; for(;;){ env = getenv("SOME_VARIABLE"); if(env) puts(env); sleep(5); } } import os import time while

How to test code dependent on environment variables using JUnit?

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a piece of Java code which uses an environment variable and the behaviour of the code depends on the value of this variable. I would like to test this code with different values of the environment variable. How can I do this in JUnit? I've seen some ways to set environment variables in Java in general, but I'm more interested in unit testing aspect of it, especially considering that tests shouldn't interfere with each other. 回答1: The usual solution is to create a class which manages the access to this environmental variable, which you

How do I read an environment variable in Kotlin?

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'd like to get a certain value from an environment variable in my Kotlin app, but I can't find anything about reading environment variables in the core libraries documentation. I'd expect it to be under kotlin.system but there's really not that much there. 回答1: It is really easy to get a environment value if it exists or a default value by using the elvis operator in kotlin: var envVar : String = System . getenv ( "varname" ) ?: "default_value" 回答2: You could always go down this approach: val envVar : String ? = System . getenv (

TOMCAT_OPTS, environment variable and System.getEnv()

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use tomcat and I want to get an environment variable in my java code. To set an environment variable, I use this bash command : export TOMCAT_OPTS=-Dmy.var=foo After it I start tomcat ./startup.sh (in bin folder of tomcat) In my java code, I try to get this variable : System.getEnv("my.var") But it returns NULL. How can I do that ? I precise that if I use maven to launch tomcat and use eclipse environment tab, the variable is found ! But I need to launch tomcat like above in production mode. EDIT: when using export MY_VAR directly it runs

strncpy doesn't always null-terminate

匿名 (未验证) 提交于 2019-12-03 01:09:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using the code below: char filename[ 255 ]; strncpy( filename, getenv( "HOME" ), 235 ); strncat( filename, "/.config/stationlist.xml", 255 ); Get this message: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append. (error) Dangerous usage of 'filename' (strncpy doesn't always null-terminate it). 回答1: I typically avoid using str*cpy() and str*cat() . You have to contend with boundary conditions, arcane API definitions, and unintended performance consequences. You can use snprintf() instead.

How to get current GOPATH from code

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I get the current GOPATH from a block of code? runtime only has GOROOT : // GOROOT returns the root of the Go tree. // It uses the GOROOT environment variable, if set, // or else the root used during the Go build. func GOROOT() string { s := gogetenv("GOROOT") if s != "" { return s } return defaultGoroot } I could make a function that has GOROOT replaced with GOPATH , but is there a buildin for this? 回答1: Use os.Getenv From docs: Getenv retrieves the value of the environment variable named by the key. It returns the value, which will

Strange behaviour for setenv & getenv in OS X Yosemite

非 Y 不嫁゛ 提交于 2019-12-02 04:09:54
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 env vars via $VARNAME , which doesn't work in my case. ursa As I wrote in section Issues / problems

PHP获取环境变量

ぃ、小莉子 提交于 2019-12-01 05:05:30
使用PHP的exec等函数与:Linux进行交互是很常见的方式,但是有时候发现,在终端里面通过命令行模式运行的代码可行,放到网站上去访问就出问题了,这里主要是因为在通过Nginx调起PHP-FPM的时候,会存在一些参数的配置问题下面就简单介绍一下这两种方式。 解决-PHP-FPM模式 通过Nginx传递 如在nginx的配置里设置: fastcgi_param ENV_XXX 123456; 每次页面请求nginx都会将此变量传递给php,php可以通过getenv函数或$_SERVER全局变量获得。 通过PHP-FPM配置传递 1234567891011121314151617 ; Clear environment in FPM workers; Prevents arbitrary environment variables from reaching FPM worker processes; by clearing the environment in workers before env vars specified in this; pool configuration are added.; Setting to "no" will make all environment variables available to PHP code; via getenv(),