Take over STDOUT / STDERR for Perl embedded in C application

W

William

Hello,

I am trying to embed Perl in a C++ application. I have a window that
takes input, when user hits return, the input is sent to Perl for
evaluation. I then want to display the input back to the user in the
window and display it differently for error versus normal output.

I've searched the web, but can't seem to find a clear example of how to
do this in C.

Presently, after calling result = perl_eval_pv() to eval the user
input, I do SvPV(result, PL_sa) and the result goes to my window. The
result is a code indicating success etc.

However, this leaves stdout and stderr still going to the shell where
my app was launched.

I would like a pointer to an example of this kind of thing being done
so I can emmulate it.

I've found many places where this question is asked but no clear
answer.

Thanks.

-William
 
C

Chris Johnson

William said:
Hello,

I am trying to embed Perl in a C++ application. I have a window that
takes input, when user hits return, the input is sent to Perl for
evaluation. I then want to display the input back to the user in the
window and display it differently for error versus normal output.

I've searched the web, but can't seem to find a clear example of how to
do this in C.

Presently, after calling result = perl_eval_pv() to eval the user
input, I do SvPV(result, PL_sa) and the result goes to my window. The
result is a code indicating success etc.

However, this leaves stdout and stderr still going to the shell where
my app was launched.

I would like a pointer to an example of this kind of thing being done
so I can emmulate it.

I've found many places where this question is asked but no clear
answer.

Thanks.

-William

This is more a question about C++ than Perl, so you're a bit offtopic.
Try a C++ or C newsgroup.

Now, if you wanted, I expect you could probably run the C program from
Perl, and for that, the IPC::Open3 module would be useful. (I haven't
been able to find a C/C++ equivalent. I suspect it may involve multiple
threads.)

If you've still got your heart set on running the perl from the C, I
suppose you could open a couple FIFOs.
 

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
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top