推荐学习书目
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 · Jan 27, 2016 · 2269 views
    This topic created in 3826 days ago, the information mentioned may be changed or developed.
    《嗨翻 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  
       Jan 27, 2016
    试试别的 exec 系列函数.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2818 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:59 · PVG 15:59 · LAX 00:59 · JFK 03:59
    ♥ Do have faith in what you're doing.