I'm writing a program with different moduals and functions. Basically the program opens a child
using a fork than execl and pipes are created to
communicate between parent and child. What I can't seem to do is write from the parent to the child after I have left the function that opens the child. In on .h file I have:
#define fdwr (rdfile[1]) //simple short cuts
#define fdrd (wrfile[0]) // to handles
extern int rdfile[2];
extern int wrfile[2];
in the .cpp file used to open the child I have defined:
int rdfile[2];
int wrfile[2];
the function looks like:
int OpenTelnet(char *pszAddress, char *pszPort)
{
if (tnproc) return 0;
pipe(rdfile);
pipe(wrfile);
tnproc = fork();
if (!tnproc)
{
dup2(rdfile[0], fileno(stdin));
dup2(wrfile[1], fileno(stdout));
close(fileno(stderr));
setpgrp();
execl(TELNET, TELNET, pszAddress, pszPort, NULL);
}
}
As I say as long as I am in this function I can write to the child using
write(fdwr, szBuffer, strlen(szBuffer));
The problem is writing later in the program. Can
you direct me.
Thanks inadvance.