我使用以下命令设置了环境变量:
QUERY_STRING='This is my query string'
这是我的程序:
#include <stdio.h>
#include <stdlib.h>
void main (int argc, char *argv[])
{
printf("%s\n", getenv("QUERY_STRING"));
}
这是我运行程序时得到的:
mantis@toboggan /testing/cgi_download/temp $ echo $QUERY_STRING; ./a.out
This is my query string.
Segmentation fault
mantis@toboggan /testing/cgi_download/temp $
看起来好像没有设置环境变量,所以getenv()
返回一个NULL
.
我真的不知道为什么这不起作用。$PATH 等其他变量可用。如何设置此环境变量以便我的程序可以使用它?
unname -a:
Linux toboggan 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l GNU/Linux