以下是引用林月儿在2016-1-20 20:36:55的发言:
code?
c 代码
程序代码:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(int argc, char* argv[]) {
char* feeds[] = { "http://feed.xbeta.info/"
, "http://feed."
, "http://"
};
int feedsLen = sizeof(feeds)/sizeof(*feeds);
printf("feedsLen=%d\n", feedsLen);
char* phrase = argv[1]; //搜索关键字
for (int i = 0; i < feedsLen; i++) { //遍历RSS源
char var[255];
sprintf(var, "RSS_FEED=%s", feeds[i]);
char* vars[] = {var, NULL}; //环境变量数组
if (execlpe("python", "python",
"./rssgossip.py", phrase, NULL,
vars/*将这里的 vars 改为 NUll,运行不报错,就是 rssgossip.py 拿不到 RSS_FEED 环境变量*/) == -1) {
fprintf(stderr, "Can't run script: %s\n", strerror(errno));
return 1;
}
}
puts("should not see this message");
return 0;
}
rssgossip.py:
程序代码:
import sys
import os
print sys.argv
print os.environ['path']
print os.environ('RSS_FEED')
#print os.getenv('RSS_FEED')