Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i was working in android ndk and found that the following function
C++
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

C++
#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:-


C++
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 function
C++
int err = service->dump(STDOUT_FILENO, args);

into the file.

Can anybody tell this?
Posted

1 solution

C++
FILE* f = fopen("logfile", "a+");
int err = service->dump(fileno(f), args);

fileno() is in <stdio.h>.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900