V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
km5ogs
V2EX  ›  Python

《嗨翻 C 语言》p418 页 newshound.c(调用 python) 运行失败

  •  
  •   km5ogs · 2016-01-27 15:42:13 +08:00 · 1842 次点击
    这是一个创建于 3028 天前的主题,其中的信息可能已经有所发展或是发生改变。
    《嗨翻 c 语言》书中的 p418 页,运行 newshound.c 报错:"python 应用程序正常初始化(0xc0150004)失败"。

    环境 winxp + tdm-gcc-4.9.2.exe + python-2.7.9.msi

    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.appinn.com/"
    , "http://fullrss.net/a/http/feed.iplaysoft.com/"
    };
    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')
    firebroo
        1
    firebroo  
       2016-01-27 21:21:02 +08:00
    试试别的 exec 系列函数.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2802 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:34 · PVG 16:34 · LAX 01:34 · JFK 04:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.