Redirecting I/O in embedded Python

B

Bertram Scharpf

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
 
H

Heather Coppersmith

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
 
B

Bertram Scharpf

Hi Heather,

Heather Coppersmith said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,055
Members
47,659
Latest member
salragu

Latest Threads

Top