FAQ
Hi,

I'm extending a windows application (C++) by embedding Python calls. It
seems to be a known problem that windows applications detach immediately
from the calling console, so that all output to stdout (from both C++
and Python) doesn't get shown anywhere.

A workaround seems to be the allocation of a windows console and
redirecting stdout to it:

AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);

Still, this console only shows the output of my C++ application, not the
output of the embedded python calls.

The following code
Py_Initialize();
std::cout << "start printing..." << std::endl;
PyRun_SimpleString("print('PRINT')\n");
std::cout << "done printing." << std::endl;

only prints

start printing...
done printing.

Does anybody know how to fix this issue? Basically I want to get an
ipython console running in the background of my Windows app, so that I
can process its data.


Cheers,


Thomas

Search Discussions

  • Thomas Schreiner at Sep 26, 2007 at 8:40 pm
    Hi,
    I'm extending a windows application (C++) by embedding Python calls.
    It seems to be a known problem that windows applications detach
    immediately from the calling console, so that all output to stdout
    (from both C++ and Python) doesn't get shown anywhere.

    A workaround seems to be the allocation of a windows console and
    redirecting stdout to it: >
    AllocConsole(); freopen("conin$", "r", stdin); freopen("conout$",
    "w", stdout); freopen("conout$", "w", stderr); >
    Still, this console only shows the output of my C++ application, not
    the output of the embedded python calls. >
    The following code Py_Initialize(); std::cout << "start printing..."
    << std::endl; PyRun_SimpleString("print('PRINT')\n"); std::cout <<
    "done printing." << std::endl; >
    only prints >
    start printing... done printing. >
    Does anybody know how to fix this issue? Basically I want to get an
    ipython console running in the background of my Windows app, so that
    I can process its data.
    for the files: I got close to what I wanted using WConio:
    http://newcenturycomputers.net/projects/wconio.html

    I basically wrote my own class that I used for overwriting stdin and
    stdout and that internally used WConio. This still doesn't allow
    readline functionality from windows consoles, but still it's better than
    nothing.

    If you have any additional ideas, especially about how I can still use
    readline despite of overwriting stdin/stdout, please CC me.

    Cheers,


    Thomas



    --
    Thomas Schreiner, AGBS
    Max Planck Institute for Biological Cybernetics
    72076 Tuebingen / Germany

    http://www.isistius.de

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 19, '07 at 12:17p
activeSep 26, '07 at 8:40p
posts2
users1
websitepython.org

1 user in discussion

Thomas Schreiner: 2 posts

People

Translate

site design / logo © 2023 Grokbase