I don't know if this is the right newsgroup because the question is maybe a bit linux specific so if not slap me ;-)
I'm trying to send the output of a perl-script to a socket.
So I'm opening a pipe to the program (FILE fp = popen("foobar.pl", "r")) and read and write it directly to the socket.. This is my code:
------
while(!feof(fp))
{
bytes = fread(b,1,1024,fp);
fwrite(b,1,bytes,sock);
}
------
b was defined like this: b = malloc(1025); and is freed later.
This works correctly if the output of './foobar.pl' is very small.. But unfortunately, if it gets bigger I get the error: 'Broken pipe'.
The debuggers output is:
------
Program received signal SIGPIPE, Broken pipe.
0x400c3868 in write () from /lib/libc.so.6
(gdb) backtrace
#0 0x400c3868 in write () from /lib/libc.so.6
#1 0x40126308 in ?? () from /lib/libc.so.6
#2 0x4007cb0d in _IO_file_write () from /lib/libc.so.6
#3 0x4007b688 in _IO_do_write () from /lib/libc.so.6
#4 0x4007cca8 in _IO_file_xsputn () from /lib/libc.so.6
#5 0x40073959 in fwrite () from /lib/libc.so.6
#6 0x08049317 in send_sock (fp=0x804c668, sock=0x804c050, mode=0x804997d "cgi") at shttpd.c:29
#7 0x080491e1 in serve (fp=0x804c050) at serve.c:108
#8 0x0804960d in main (argc=1, argv=0xbffff6d4) at shttpd.c:108
------
Regards
Pascal Ehlert