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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |