I tried to do something similar awhile back. I came to
conclusion to use "named pipes" or better yet sockets to
communicate between c and perl. I have a c example below,
just rewrite your cpp program to read the data from the pipe,
instead of STDIN. There are some tricks involved getting
it all to run smoothly, but this gives you the idea.
#include <stdio.h> int main(void){ FILE *fp; char *line; if (mkfifo ("my-pipe", 0755) != 0) {printf ("Could not make this fifo or it exists\n");} else {printf ("FIFO was successfully made!\n");} fp = fopen ("my-pipe", "r"); while (fgets (line,256, fp)){ printf ("message: %s", line); } close (fp); }
 Now your perl script should just write to the pipe
#!/usr/bin/perl &send_data; sub send_data{ $|=1; open(FIFO, "> my-pipe") or die $!; print "What's your age?\n"; $input = <STDIN>; chomp $input; print FIFO "$input\n"; close(FIFO); }

In reply to Re: redirecting input to console by zentara
in thread redirecting input to console by arkamedis21

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.