470,644 Members | 1,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,644 developers. It's quick & easy.

Redirecting I/O in embedded Python

Hi,

in one of my C programs, I call embedded Python code. Now, I
would like to redirect stdin/stdout to strings I can assign
to/read out within the C code.

This should be a solvable problem creating modules that have
a member function 'write' or 'readline' respectively and
assigning them to sys.stdin and sys.stdout.

Before I do this work, I would like to ask if there is a
reported standard way to do it or if there is even the
finished code to be obtained anywhere on the web.

Thanks in advance,

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Jul 18 '05 #1
2 2139
On 25 Jun 2004 12:11:48 GMT,
Bertram Scharpf <b.*******@tesionmail.de> wrote:
Hi,
in one of my C programs, I call embedded Python code. Now, I
would like to redirect stdin/stdout to strings I can assign
to/read out within the C code. This should be a solvable problem creating modules that have
a member function 'write' or 'readline' respectively and
assigning them to sys.stdin and sys.stdout. Before I do this work, I would like to ask if there is a
reported standard way to do it or if there is even the
finished code to be obtained anywhere on the web.


Put the library reference under your pillow tonight, and read the
sections on stringio and cstringio in the morning.

Regards,
Heather

--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
Jul 18 '05 #2
Hi Heather,

Heather Coppersmith <me@privacy.net> schrieb:
On 25 Jun 2004 12:11:48 GMT,
Bertram Scharpf <b.*******@tesionmail.de> wrote:
Hi,
in one of my C programs, I call embedded Python code. Now, I
would like to redirect stdin/stdout to strings I can assign
to/read out within the C code.

This should be a solvable problem creating modules that have
a member function 'write' or 'readline' respectively and
assigning them to sys.stdin and sys.stdout.

Before I do this work, I would like to ask if there is a
reported standard way to do it or if there is even the
finished code to be obtained anywhere on the web.


Put the library reference under your pillow tonight, and read the
sections on stringio and cstringio in the morning.


Yes, I did already think of that solution. But compared to
that mentioned above, it wouldn't be less effort in
programming for me, but rather a loss in efficiency I
suppose. (Additional modules would be loaded and strings
would be copied once more.)

Thank you, anyway.

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Alexander May | last post: by
3 posts views Thread by paul koelle | last post: by
3 posts views Thread by David Douard | last post: by
3 posts views Thread by Godzilla | last post: by
9 posts views Thread by Fuzzyman | last post: by
20 posts views Thread by Jack | last post: by
1 post views Thread by andy | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.