jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
At the end of this post I've attached the C program.#! /usr/bin/perl open OUT ,">&63" ; print OUT "this is a message\n" ; close OUT ;
#include <unistd.h> #include <stdio.h> #include <fcntl.h> main() { const int RESPONSE_FD = 63; int pfd[2], status, size; char buffer[100]; status = pipe(pfd); if(status == -1) { printf("Could not open pipe\n"); exit(1); } else { printf("The filedescriptors are: %d %d\n", pfd[0], pfd[1]); } status = fork(); if(status == 0) { printf("This is the child\n"); status = dup2(pfd[0], RESPONSE_FD); if(status == -1) { printf("dup2 failed\n"); exit(1); } close(pfd[1]); close(pfd[0]); while(read(STDIN_FILENO, buffer, sizeof(buffer))>0) { printf("%s", buffer); } } else { printf("This is the parent\n"); system("my_prog.pl"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: communication between C and perl
by almut (Canon) on Feb 09, 2007 at 14:06 UTC | |
by jeanluca (Deacon) on Feb 09, 2007 at 15:13 UTC | |
|
Re: communication between C and perl
by Joost (Canon) on Feb 09, 2007 at 09:47 UTC | |
|
Re: communication between C and perl
by jesuashok (Curate) on Feb 09, 2007 at 10:35 UTC | |
|
Re: communication between C and perl
by jeanluca (Deacon) on Feb 09, 2007 at 12:06 UTC | |
by zentara (Cardinal) on Feb 09, 2007 at 12:27 UTC | |
by jeanluca (Deacon) on Feb 09, 2007 at 13:01 UTC | |
by zentara (Cardinal) on Feb 09, 2007 at 16:36 UTC | |
by jeanluca (Deacon) on Feb 09, 2007 at 19:03 UTC |