Dear Monks,
I need to setup a communication link between a C program and a perl program. This C program executes the perl script and reads the output from the perl script. This perl script writes its output to a
file-descriptor#! /usr/bin/perl
open OUT ,">&63" ;
print OUT "this is a message\n" ;
close OUT ;
At the end of this post I've attached the C program.
Anyway, this doesn't work at all. However, when I use 0 instead of 63, everything works fine!!
Any suggestions what I'm doing wrong here with the file-descriptor 63 ?
Thnx a lot
LuCa
C program:
#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");
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.