Take over STDOUT / STDERR for Perl embedded in C application

Discussion in 'Perl Misc' started by William, Oct 5, 2005.

  1. William

    William Guest

    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
    William, Oct 5, 2005
    #1
    1. Advertising

  2. William wrote:
    > 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.
    Chris Johnson, Oct 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Landenburer

    redirecting stderr and stdout

    Jon Landenburer, May 12, 2004, in forum: Perl
    Replies:
    1
    Views:
    11,197
    Joe Smith
    May 13, 2004
  2. ladygrinningsoul

    Reading stdout and stderr separately

    ladygrinningsoul, Nov 18, 2004, in forum: Perl
    Replies:
    3
    Views:
    1,031
    Alexey A. Kiritchun
    Apr 25, 2005
  3. VisionSet
    Replies:
    6
    Views:
    9,616
    Sudsy
    Sep 20, 2003
  4. Guest
    Replies:
    3
    Views:
    1,167
    Guest
    Jan 11, 2004
  5. Andre
    Replies:
    7
    Views:
    465
    Dan Pop
    Jul 21, 2003
Loading...

Share This Page