472,129 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,129 software developers and data experts.

Windows embedding problems with stdin and stdout


I have Python embedded with my other code, and when my other code opens
a console and redirects stdout, stdin and stderr to it, then calls
PyRun_InteractiveLoop, it immediately returns with an EOF.

After some debugging the reason for this appears to be that the stdin
and stdout that the ReadLine function in the tokeniser include are not
affected by my redirection and refer to a non-terminal so don't stall
waiting for input from my console.

This is the C code, effectively. It should suffice as an
example of what I am doing, although as it is from memory,
it may have minor semantic errors, please ignore them:

/* This goes nowhere because the old stdin and stdout are
no longer valid */

/* This opens a console and redirects the in, out and err */
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "a", stdout);
freopen("CONOUT$", "a", stderr);

/* I've tested stdin, stdout and stderr at this point and they
all work correctly on the opened console window. */
printf("Test stdout working, isatty(stdin) = %d\n",
/* Returns 64 */

/* This call returns immediately. The stdin and stdout when
the code gets to the actual reading, return isatty(fileno(x))
== 0 and so it uses the non terminal reading. */
PyRun_InteractiveLoop(stdin, "Opened Console");

Can anyone help me? I have no idea how to get Python to adopt
the new stdin, stdout and stderr, but I have to assume it is
pretty straightforward.


Aug 10 '05 #1
0 1699

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mark McEahern | last post: by
1 post views Thread by Vincent Touquet | last post: by
5 posts views Thread by Jeff Learman | last post: by
4 posts views Thread by Jonathan Fine | last post: by
2 posts views Thread by Greg Ercolano | last post: by
reply views Thread by Thomas Schreiner | last post: by
reply views Thread by Gabriel Genellina | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.