Re: How do I redirect server's standard output to socket?
- From: andrew@xxxxxxxxxxxxxxxxxxxx (Andrew Gabriel)
- Date: 29 Dec 2005 09:01:21 GMT
In article <1135841257.496274.321580@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
thisrule@xxxxxxxxx writes:
> I made two process. One is use for a socket server in remote host, the
> other is client.
> Socket server includes a big library and will be run in the background,
> and client program has GUI with Qt library.
> I want server standard output to redirect to client program.
>
> To do it I tried to use dup2() function, following
> dup2( socket_descriptor, 1 ); // standard out to socket
> dup2( sokcet_descriptor, 2 ); // standard err to socket
>
> Then, write( 1, "message\n", 8 ) works good.
> The string, "message" displayed in the client program.
> But printf( "message\n" ) does not work.
It is probably buffered.
Either tell the stdio library to force the buffer out when
needed with fflush(stdout), or tell it to always force the
buffer out when it gets to a '\n' by setting the buffering
policy with something like:
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
Note you should probably be using fdopen() after a dup2()
call if you are going to use stdio functions like printf(),
so the stdio library is properly initialised for those file
descriptors.
--
Andrew Gabriel
.
- References:
- How do I redirect server's standard output to socket?
- From: thisrule
- How do I redirect server's standard output to socket?
- Prev by Date: Re: lsof and the FD column
- Next by Date: Re: Disk labels (c0t0d0 & c1t0d => c2t0d0 & c3t0d0) weirdness
- Previous by thread: Re: How do I redirect server's standard output to socket?
- Next by thread: Single sign-on daemon
- Index(es):
Relevant Pages
|