blocking system calls - question
I have a following piece of code
printf("creating log file ... "); result = ee_log.init(); if(result == true) { printf("success \n"); } else if(result == false) { perror("error - > Error in opening log file."); return false; } but while running the program, I get "error - > Error in opening log file." printed before "creating log file ... ". Is this something to do with blocking system calls ? It has to be like this creating log file ... error - > Error in opening log file.: Permission denied But What I am getting in the terminal is error - > Error in opening log file.: Permission denied creating log file ... |
Not really sure, but is perror outputting to stdout or stderr ? it may be related, because I think the printf is to stdout, and perror is to stderr... I am not sure how to change the order, but I think there would be a way. If you want you can redirect one or the other by redirecting 1> /path/stdout.txt 2> /path/stderr.txt
more info, and how to redirect both can be found here: http://www.cpqlinux.com/redirect.html hope this helps |
It's because stdout is line buffered and stderr is not buffered at all. So the "creating log file..." will be printed when the program terminates. If you add a \n to the "creating log file..." message, the buffer will be flushed.
|
Quote:
Code:
fflush(stdout); |
All times are GMT -5. The time now is 02:21 AM. |