Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'that?': 0.05; 'idea?': 0.09; 'parsed': 0.09; 'skip:g 60': 0.09; 'solution,': 0.09; 'steps:': 0.09; 'subject:parsing': 0.09; 'python': 0.11; '(3,': 0.16; '(int': 0.16; 'fine.': 0.16; 'skip:g 70': 0.16; 'stdout': 0.16; 'typedef': 0.16; 'trying': 0.19; 'written': 0.21; 'seems': 0.21; 'shell': 0.22; 'print': 0.22; 'creating': 0.23; 'char': 0.24; 'x-mailer:microsoft outlook express 6.00.2900.5931': 0.24; 'initial': 0.24; "i've": 0.25; 'skip:" 40': 0.26; "doesn't": 0.30; "i'm": 0.30; 'embed': 0.31; 'embedding': 0.31; 'null;': 0.31; 'produces': 0.31; 'file': 0.32; 'to:name:python-list': 0.33; 'subject:the': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'but': 0.35; 'done': 0.36; 'charset:us- ascii': 0.36; 'similar': 0.36; 'should': 0.36; 'so,': 0.37; 'expected': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'simply': 0.61; 'grab': 0.64; 'faster.': 0.84; 'grabbing': 0.84; 'spawned': 0.84 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed; reply-type=original From: Gisle Vanem To: Python-list Subject: Calling Py_Main() and parsing the output from C Date: Sat, 10 Aug 2013 15:09:31 +0200 X-Priority: 3 X-MSMail-priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376143781 news.xs4all.nl 15874 [2001:888:2000:d::a6]:40090 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52307 Hello Python & C-experts. I'm trying to embed python27.dll in a C-program written in MingW-gcc 4.7.2. I've successfully done these initial steps: typedef int (*Py_Main_t) (int argc, char **argv); handle = LoadLibrary ("python27.dll"); py_main = (Py_Main_t) GetProcAddress (handle, "Py_Main"); argv[0] = who_am_I; /* the .exe of the embedding program. python*.dll doesn't seems to care what this is */ argv[1] = (char*) "-c"; argv[2] = PYTHON_CMD; /* see below */ argv[3] = NULL; rc = (*py_main) (3, argv); DEBUG: pyembed.c(76): Calling Py_Main(): argv[0] = "G:\vc_2010\VC\Projects\EnvTool\src\envtool.exe" argv[1] = "-c" argv[2] = "import sys;[sys.stdout.write('%s\n' % p) for (i,p) in enumerate(sys.path)]" argv[3] = NULL. Which produces the expected 'sys.path[]: g:\Programfiler\Python27\lib\site-packages\pyzmq-2.2.0.1-py2.7-win32.egg g:\Programfiler\Python27\lib\site-packages\nose-1.2.1-py2.7.egg ... But I'd like to grab the stdout from Py_Main() into a pipe, mmap-file or similar for the calling program to parse. Before I used the embedding solution, I simply spawned python.exe using my shell and popen(). Then parsed the output using fgets(). This work fine. But I'd like to try embedding now. Since avoiding the shell should be faster. No? How can I accomplish the grabbing of Py_Main() output simplest? Is creating a memory-mapped file in the calling program a good idea? Can Py_Main() print to that? If so, how? I'm on Win-XP SP3. --gv