-
pipe stream data I/O
I am trying to have two programs share information. The original running program streams data to a pipe and the second program should read from that pipe concurrently. They are two different executables. The way I have it now is the first program executes the second program with a system call on UNIX.
Code:
first program
int
main(int argc, char *argv[])
{
//pipe is created
if(pipe(writepipe)==-1) {
perror("Pipe writepipe creation failed.\n"); //Pipe writepipe created
exit(1);
}
else
printf("Pipeline write created.\n");
//pipe is wrote to
p1=draw_geom_buf.value[0];
data=p1;
write(writepipe[0],&data,sizeof(data));
//second program is executed
case XK_F4: //>>DDC
printf("Displaying new window\n");
system("./program2&");
second program
data is read from pipe? NO
int writepipe[2];
float input;
read(writepipe[1],&input,sizeof(input));
cout << input << endl;
It prints out a bunch of zeros, is there anyway to fix this?
Thanks
DC
-
Nice try with the code tags, but you need [] brackets, not {}. See here .
I'll move this thread to the Linux forum too.