How to take console data into file?

i was working in android ndk and found that the following function int err = service->dump(STDOUT_FILENO, args);
print the dump of service on console but it to print it in file,how can i do that
i have written the following function to take data in buffer
1
2
3
4
5
6
7
8
9
10
11
12
#define LOGFILE "C:\\MyServices\\dump.txt"
#define buffer 2500
int WriteToLog(char* str)
{
   FILE* log;
   log = fopen(LOGFILE, "a+");
   if (log == NULL)
      return -1;
   fprintf(log, "%s\n", str);
   fclose(log);
   return 0;
}


if want to print something in file i used to do like this:-
1
2
3
4
5
6
 for (size_t i=0; i<N; i++) {
            sp<IBinder> service = sm->checkService(services[i]);
            if (service != NULL) {
            	sprinf(buffer,"services[%d] = %s",i,services[i]);
            	WriteToLog(buffer);
                aout << "  " << services[i] << endl;



but don't know how to take data from this functionint err = service->dump(STDOUT_FILENO, args); into the file.

Can anybody tell this?
i think int err = service->dump(STDIN_FILENO, file pointer to open file); this should work
Topic archived. No new replies allowed.