[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] C - læs output fra kø rende program



Jeppe Larsen wrote (28-01-2006 21:33):
Jeg sidder med en opgave hvor jeg skal bruge output fra et program som
input i et andet. Programmet der laver output kører bare i en uendelig
løkke og spytter en streng ud ca. hvert sekund. I stil med:


while(1) { printf("hum hum\n"); sleep(1); }

Hvordan får jeg løbende læst disse linier ind i et andet program? Almene
funktioner som fgets eller getc osv. duer ikke. Vel fordi at normalt er
input-streams færdige når de læses eller noget. Ligeledes bliver der
heller aldrig skrevet til en fil, hvis man starter programmet med:

./prog > fil

Så hvordan håndteres dette særtilfælde?

Det er nok fordi stdout er bufferet til en fil eller pipe. Du ser så ikke noget output før bufferen er fuld.


Smid en fflush(stdout) ind efter hver printf, så du får sendt output før hver sleep.

--
René Seindal (sslug@sslug)







 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-02-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *